Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS different constraints for different devices

I have a ViewController designed for iPhone SE

enter image description here

As you can see I also have a constraint Align Top to: Safe Area Equals 75

The question is, is it possible to change this value for iPhone 8 and iPhone 8 Plus? For example:

  • SE = 75
  • 8 = 85
  • 8 Plus = 105
like image 751
xskit Avatar asked Feb 06 '18 20:02

xskit


People also ask

What are iOS constraints?

With constraints, you can say “these items are always lined up in a horizontal row” or “this item resizes itself to match the height of that item.” Constraints provide a layout language that you add to views to describe geometric relationships. The constraints you work with belong to the NSLayoutConstraint class.

How do you vary for traits?

Click the 'Vary for Traits' button at the bottom right. A popover appears, allowing us to select which size class traits we want to create a layout variation for, e.g width, height, or both. Selecting a size class trait creates a variation based on the size class for the currently selected device configuration.

What is adaptive layout in iOS?

The introduction of Adaptive Layout caused a huge paradigm shift for iOS app designers. By using it, you can now create a single layout for your app which works on all current iOS devices — without crufty, platform-specific code! This tutorial serves as your introduction to Adaptive Layout.


1 Answers

Easy way!

To overcome this issue I created a small library so you don't have to write a single line of code just assign the class (NSLayoutHelper) to your constraint and you'll be able to update your constraint for all the devices differently.

enter image description here

For updating constraints

enter image description here

Output

enter image description here

like image 70
tryKuldeepTanwar Avatar answered Sep 17 '22 14:09

tryKuldeepTanwar