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
Image size settings and Center
More attention SwiftUI tutorials and code columns