简体   繁体   中英

How to maintain UIView ratio across different devices using Autolayout?

I have one UIView in LaunchScreen .

在此处输入图片说明

I have added following constraint to this UIView .

在此处输入图片说明

I want my red view always 35% of the screen.

I have calculated the height of RedView as : My ViewController height is 667 I calculated the 35% and assigned to RedView .

I want to know that is my approach is correct. As their is very slight change in width of iPhone6Plus and huge change in height.

Is my constraint correct for 35:65 screen.

Instead of giving Aspect ratio you could also give it a multiplier for 35%.

Step 1: Pin RedView from 3 sides, Right-Top-Left

Step 2: Make RedView and ViewController's main view to Equal height.

Step 3: Select RedView's equal height constraint and go to it's attribute inspector. (4th right tab)

Step 4: Change Multiplier value to 0.35 .

Now RedView will be always 35% of your main screen in both Orientations.

总是35%

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