设置图像的固定大小。

5
如何在SwiftUI中设置图像的固定大小?目前我的图像非常大。
目前我有以下结构:
struct TweetCell: View {
     var profileImage: Image
     var body: some View {
         HStack {
              profileImage
             VStack {
            ...
         }
    }
  }
}
2个回答

10

其中一种方法是通过

profileImage.resizable().frame(width: 50, height: 50)

1
如果我不调用resizable(),会有什么区别? - SwiftiSwift
1
尝试一下!它不会调整图像大小,而是从中裁剪出一个50x50的矩形。 - tsp
1
您还可以添加 .scaledToFit().scaledToFill(),具体取决于您希望不同纵横比的图像如何填充视图。Fit 保留长宽比,fill 扭曲图像。 - Jacob

1
There are multiple ways to set fixed size to Image

1) Image("yourImage").frame(width: 25, height: 25, alignment: .center)

2) Image("yourImage").resizable().frame(width: 25, height: 25, alignment: .center)
3) Image("yourImage").frame(width: 25, height: 25, alignment: .center).clipped()

Attached the screenshots for all.

image1

image2

image3


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接