我在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)
当前回答
Image(systemName: "person.fill")
.font(.system(size: 13))
如果你使用systemName也可以。
其他回答
Image(systemName: "person.fill")
.font(.system(size: 13))
如果你使用systemName也可以。
204
如果我们在Assets.xcassets中有一个大图像。然后调整大小 首先,我们必须使用 resized(),然后使用frame()。
Image(room.thumbnailImage)
.resizable()
.frame(width: 32.0, height: 32.0)
你还可以使用:
Image("Example")
.scaleEffect(NumberWithSizeBetweenZeroAndOne)
在图像名称后使用. resized()方法。 确保在进行任何修改之前需要声明. resized()的用法。
是这样的:
Image("An Image file name")
.resizable()
//add other modifications here
SwiftUI为我们提供了. resized()修饰符,它可以让SwiftUI调整图像的大小以适应其空间
struct ContentView: View {
var body: some View {
Image("home")
.antialiased(true) //for smooth edges for scale to fill
.resizable() // for resizing
.scaledToFill() // for filling image on ImageView
}
}