Image of SwiftUI set the size of the entry and center (2020 Tutorial)

Image of SwiftUI set the size of the entry and center (2020 Tutorial)


Technical Points

  • How to get the screen size
UIScreen.main.bounds.width
  • How to set medium size photo
 .resizable()
.scaledToFit()

Code

import SwiftUI

struct ProductCard: View {
    var body: some View {
        VStack(alignment:.leading,spacing: 0){
            Image("circle")
            .resizable()
            .scaledToFit()
                .frame(minWidth:nil,
                       idealWidth: nil,
                       maxWidth: UIScreen.main.bounds.width,
                       minHeight: nil,
                       idealHeight: nil,
                       maxHeight: 300,
                       alignment: .center
                       )
        }
    }
}

effect

41085-1c8f2a50b47234ac.jpg
Image size settings and Center

More attention SwiftUI tutorials and code columns

Published 637 original articles · won praise 4 · views 50000 +

Guess you like

Origin blog.csdn.net/iCloudEnd/article/details/104074484