Reputation: 151
I have a UIImageView
that needs to be centered and have a width that's equal to the screen width and some height that grows proportionally with the width. So for instance, for the iPhoneXR I have:
And on the iPad 9.7 it would be:
So basically the image just scales proportionally with each screen size. I have already figured out how to center it using constraints, but I'm lost on how to get it to scale proportionally. I've played around with the auto resizing options and constraints to no avail. I struggle so badly with these storyboards, wish I could just code it! Is this even possible in a LaunchScreen storyboard?
Upvotes: 2
Views: 3341
Reputation: 383
You can not give constraints to a view w.r.t viewController in LaunchScreen.storyboard because our view hierarchy has not loaded till that point of time. You can give an imageView constraints w.r.t itself. CTRL drag on the imageView and select height, width or aspect ratio.
Though the recommended way will be to use another viewController that will work as LaunchScreen with some delay in segue.
Upvotes: 0
Reputation: 847
By adding proper constraint you will get your expected result. Add aspectRatio
constraint to imageView
.
All constraints as per
Upvotes: 1
Reputation: 2551
You can't execute any code inside launch screen. However, you can make it with constraints.
Set center equal to superview
, then set width
equal to superview
. Now, you can add aspectRatio
which is like 1:1
, so you imageView height
would always be equal to its width or any other ratio you want.
Example:
Upvotes: 4