简体   繁体   中英

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:

在此输入图像描述

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?

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:

在此输入图像描述

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

在此输入图像描述

All constraints as per

在此输入图像描述

You can not give constraints to a view wrt viewController in LaunchScreen.storyboard because our view hierarchy has not loaded till that point of time. You can give an imageView constraints wrt 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM