0
votes

All iPhone devices from iPhone SE to iPhone XSMax fall under same size class of compact width and regular height in Portrait mode. Then how can we add different size for UIButton in storyboard that can vary for iPhone 5s, iPhone 6 and iPhone X?

How can we use size classes for iPhones in portrait mode? Also how can we use different font sizes for different devices?

I tried to use vary for traits in storyboard but was unsuccessful to set different heights for a UIButton in different iPhone devices.

I want to set Button to be of height 30 in iPhone 4s and I want that button to grow as the device height increases and font size also should vary accordingly. Setting button's height proportional super view's height didn't yield me desired results as there are other UIElements in the storyboard.

1

1 Answers

0
votes

This can be done in a lot of different ways. You could for example

  • Use proportional height constraints
  • Not use height constraints and only constrain the distance to the screen / other elements
    • As the screen grows, the distance to the screen edge will stay the same, resulting in a bigger button
  • Set different heights for different screen sizes via code
    • You could wrap this into a NSLayoutConstraint subclass that has @IBInspectable properties, allowing you to set everything up using the Interface Builder

I think you should first think about your design again. Fixed heights usually break as soon as there are new iPhone sizes. Because of that, you should probably try to not have fixed heights for different phones and instead use equal distances to other elements or proportional constraints.

In my opinion most fixed heights are unnecessary and I'd consider them a code-smell.