I was looking at this youtube video https://www.youtube.com/watch?v=vzyd33Pv9kg regarding How Priority Constrains works. I want to do the same but instead of label I am using custom buttons with images. As you can see in the video, the author hardcoded the size of the label to 100wx100h. However regardless of the what iphone you have, the labels always be the same size. I want to accomplish the same thing, but instead I want the size of buttons (or in his case labels) be larger on iphone 5, and even larger in iphone 6 and so on. My question is how can I accomplish this? Also is it possible design this with let say 100X100 in 3.5-inch iphone then change the size dynamically change in the code depends what iphone is used? if iphone4s then use 100X100 size buttons else if iphone 5 then use 110X110 size buttons and so on?
Asked
Active
Viewed 841 times
1 Answers
3
Yes you can. Just connect your relevant constraints(width and height constraints in your case) to your view controller like usual elements. Than you can change constant property of your NSLayoutConstraints (Probably in your viewDidLoad method).
self.buttonWidthConstraint.constant = 110.;
self.buttonHeightConstraint.constant = 110.;
You also may want to change size classes to provide different constrains for each orientation.

Alp Keser
- 165
- 8
-
Sorry so new to xcode and swift. what is buttonWidthConsteaint.constant? as an example I created an outlet from my first button @IBOutlet weak var button1: UIButton! Let just increase the size so in the viewDidLoad() what should I say to increase the size? – borna Jun 28 '15 at 18:30
-
Create also another outlets from your constraints. In example above "buttonWidthConstraint" is the name of that outlet. – Alp Keser Jun 28 '15 at 19:39
-
wow, perfect, thanks that worked. now one more question. How can say if iphone5 or 5s set the H and W to 110 and if iphone 6 set the H and W to something else like 130? Can this be tested on Simulator or has to be tested on actual phones? – borna Jun 28 '15 at 19:58
-
Hi, check this link for that; http://stackoverflow.com/questions/448162/determine-device-iphone-ipod-touch-with-iphone-sdk – Alp Keser Jun 29 '15 at 07:14