简体   繁体   中英

SwiftUI view like UIKit UIView, How to change the size of the image

Is there any view in swiftui that is similar to UIKit UIView

There is an EmptyView in swiftui does anyone know what this view do

        Image("image")
        .resizable()
        .aspectRatio(3/2, contentMode: .fill)

This messes up the image is there any other way that i can resize the image

In SwiftUI, primitive views like Color, Text, Image etc act like UIView. To change a image size you just need to give it a frame and make it resizable() first.

struct ContentView : View {

    var body: some View {

         Image("your image name")
            .resizable()
            .frame(width: 300, height: 300)
    }
}

Hope it will help.

In SwiftUI, to change the image size there is 2 ways

1) Make it resizable and give some frame to Image

   Image("image name")
      .resizable()
      .frame(width: 10, height: 10, alignment: .center)

2) Make it resizable and scaleToFit property to Image

   Image("image name")
      .resizable()
      .scaledToFit()

For more customization of Image please look at below link https://developer.apple.com/documentation/swiftui/image/3269652-frame

I hope it will help you!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM