我在Assets.xcassets中有一个大图像。如何用SwiftUI调整这张图片的大小使它变小?
我试着设置框架,但它不起作用:
Image(room.thumbnailImage)
.frame(width: 32.0, height: 32.0)
我在Assets.xcassets中有一个大图像。如何用SwiftUI调整这张图片的大小使它变小?
我试着设置框架,但它不起作用:
Image(room.thumbnailImage)
.frame(width: 32.0, height: 32.0)
当前回答
另一种方法是使用scaleEffect修饰符:
Image(room.thumbnailImage)
.resizable()
.scaleEffect(0.5)
其他回答
这个怎么样:
struct ResizedImage: View {
var body: some View {
Image("myImage")
.resizable()
.scaledToFit()
.frame(width: 200, height: 200)
}
}
图像视图为200x200,但图像保持原始宽高比(在该帧内重新缩放)。
另一种方法是使用scaleEffect修饰符:
Image(room.thumbnailImage)
.resizable()
.scaleEffect(0.5)
在图像视图上使用带有动态类型的字体修饰符:
Image(systemName: "nose")
.font(.largeTitle)
Image(systemName: "person.fill")
.font(.system(size: 13))
如果你使用systemName也可以。
“图像属性”的定义如下:—
Image("\(Image Name)")
.resizable() // Let you resize the images
.frame(width: 20, height: 20) // define frame size as required
.background(RoundedRectangle(cornerRadius: 12) // Set round corners
.foregroundColor(Color("darkGreen")) // define foreground colour