I have a textfield of 100 width but i want the size of this textfield change on different size screens in same manner. i do not want to give % constraint of screen to increase size. for example in 6s textfield size is 100 but on 7 size should be change on the basis of screen size.
Asked
Active
Viewed 343 times
0
-
i set fix width constraint on textfield in 6s – rajat yadav Jul 06 '17 at 10:46
-
What manner exactly? You could try to set a leading/trailing constraint? – Larme Jul 06 '17 at 10:48
-
i set width constraint to 100 and leading constraint is 50 and top is also 50 in 6s screen, now i want when move to iphone-7 textfield width is increase according to screen size and in iphone-5 width is decrease and i do not want to set multiplier to my width constraint – rajat yadav Jul 06 '17 at 10:56
-
you should use AutoLayout to get appropriate result. refer http://www.appcoda.com/auto-layout-guide/ – Neha Gupta Jul 06 '17 at 11:03
-
there is any way by which i can change the width on different screen with these constraints that i have applied? – rajat yadav Jul 06 '17 at 11:29
1 Answers
0
If you want to use constraints, you have to manually change its value accordingly to screen size. You can drag and drop your constraint properties as outlet
And you can change the constraint by accessing its constant property
self.viewWidthConstraint.constant = 20 //Or desired value

Khokim Mamarasulov
- 151
- 1
- 7
-
-
-
@rajatyadav There are some questions, with good answers in SO about Autoresizing and Auto Layout https://stackoverflow.com/questions/36434947/in-ios-whats-the-difference-between-autoresizing-autolayout-and-constraints – Khokim Mamarasulov Jul 10 '17 at 13:43
-
https://stackoverflow.com/questions/7754851/autoresizing-masks-programmatically-vs-interface-builder-xib-nib?rq=1 – Khokim Mamarasulov Jul 10 '17 at 13:45
-
And one more helpul tutorial to start with auto layout https://www.appcoda.com/auto-layout-guide/ – Khokim Mamarasulov Jul 10 '17 at 13:47