Reputation: 43
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.
Upvotes: 0
Views: 331
Reputation: 2854
This can be done in a lot of different ways. You could for example
NSLayoutConstraint
subclass that has @IBInspectable
properties, allowing you to set everything up using the Interface BuilderI 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.
Upvotes: 0