NSMoron
NSMoron

Reputation: 151

Rescale UIImageView proprtionally in Launch Screen Storyboard

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:

enter image description here

And on the iPad 9.7 it would be:

enter image description here

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

Answers (3)

Amyth
Amyth

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

Komal Goyani
Komal Goyani

Reputation: 847

By adding proper constraint you will get your expected result. Add aspectRatio constraint to imageView.

enter image description here

All constraints as per

enter image description here

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:

enter image description here

Upvotes: 4

Related Questions