Skip to main content
Clean up code
Source Link
aheze
  • 31.5k
  • 12
  • 107
  • 159

How about this:

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

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

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)

How about this:

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

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

Source Link
Confused Vorlon
  • 10.5k
  • 3
  • 49
  • 54

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)