How to resize Image with SwiftUI?

前端 未结 14 601
清歌不尽
清歌不尽 2020-12-23 19:54

I have a large image in Assets.xcassets. How to resize this image with SwiftUI to make it small?

I tried to set frame but it doesn\'t work:

Image(roo         


        
14条回答
  •  孤独总比滥情好
    2020-12-23 20:44

    How about this:

    struct ResizedImage: View {
        var body: some View {
    
                Image("myImage")
                    .resizable()
                    .scaledToFit()
                    .frame(width: 200.0,height:200)
    
        }
    }
    

    the image view is 200x200, but the image maintains the original aspect ratio (rescaling within that frame)

提交回复
热议问题