Divya Vohra
Divya Vohra

Reputation: 115

How to set width and height of an image in SwiftUI?

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)

Upvotes: 3

Views: 640

Answers (5)

Ronak Patel
Ronak Patel

Reputation: 629

var body: some View {

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

    }

Upvotes: 1

Manish Kumar
Manish Kumar

Reputation: 568

  Image("testImg")
 .resizable()
 .scaledToFit()
 .frame(width: required-width,height:required-height)

Upvotes: 0

Nayan Dave
Nayan Dave

Reputation: 1680

Try this code:

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

Upvotes: 1

Hardik Bar
Hardik Bar

Reputation: 1760

Image(restaurant.image)
            .resizable()
            .frame(width: 40, height: 40)
            .clipShape(Circle())

Upvotes: 1

Chaman Sharma
Chaman Sharma

Reputation: 636

Try this

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

Upvotes: 5

Related Questions