How to set width and height of an image in SwiftUI

2020-04-11 09:57发布

I am trying to set height and width of an image . I've tried using following code but it didn't work.

 Image("testImg")
  .frame(width: 50, height: 50)

标签: swift swiftui
5条回答
放荡不羁爱自由
2楼-- · 2020-04-11 10:06

Try this

Image("testImg")
.resizable()
.frame(width: 50.0, height: 50.0)
查看更多
够拽才男人
3楼-- · 2020-04-11 10:06
  Image("testImg")
 .resizable()
 .scaledToFit()
 .frame(width: required-width,height:required-height)
查看更多
成全新的幸福
4楼-- · 2020-04-11 10:14

Try this code:

 Image("testImg")
     .resizable()
     .scaledToFit()
     .frame(width: 50,height:50)
查看更多
狗以群分
5楼-- · 2020-04-11 10:16
Image(restaurant.image)
            .resizable()
            .frame(width: 40, height: 40)
            .clipShape(Circle())
查看更多
倾城 Initia
6楼-- · 2020-04-11 10:28
var body: some View {

            Image("yourImage")
                .resizable()
                .scaledToFit()
                .frame(width: 50.0, height:50.0)

    }
查看更多
登录 后发表回答