Reputation: 74
I have a code for View with Image in swiftUI, I wonder if the frame() function will produces different size for each devices(like iPhone 8, Xs, Xs+, etc)
struct CircleImage : View {
var body: some View {
Image("jorge")
.resizable()
.frame(width: 100, height: 100)
.clipShape(Circle())
.overlay(
Circle().stroke(Color.white, lineWidth: 4))
.shadow(radius: 10)
}
}
I have Xcode 11 with beta of course, but I don't have catalina since I have to do my work with Mojave and Catalina doesn't support it. So I can't find any clues with SwiftUI Preview.
I also tried to see above code with multiple simulators(with 8 and Xs+) and I saw that images seems have same size but I'm not sure for it.
And If the sizes are same, what is the standard size of screen? and if not, how can I find each screen's standards?
Upvotes: 1
Views: 1863
Reputation: 40539
I'm not sure I understand your question, but I'll do my best to answer. When you specify a frame(width: 100, height: 100), SwiftUI will make it 100x100 points. No matter which device. If you would like to adapt to the available space of a device, check the example I posted in this other question: https://stackoverflow.com/a/56853211/7786555
Additionally, here's the documentation to get the screen size for your current device:
The bounding rectangle of the screen, measured in points: https://developer.apple.com/documentation/uikit/uiscreen/1617838-bounds
The bounding rectangle of the physical screen, measured in pixels. https://developer.apple.com/documentation/uikit/uiscreen/1617810-nativebounds
Upvotes: 2