0

I have to add a text filed and it is 210X30 for iPhone 5. I want it to stretched according to iPhone 6 and iPhone6+. I don't want to fix the width or height of the text field and also don't want to fix the horizontal spacing from the edges of the iPhone. I want it to be flexible and maintain the ratio of the space which it has in case of iPhone 5. Kindly let me know what kind of Constraints I need to put in order to achieve that. Please let me know if my question is Unclear I will explain in detail as I am sure this scenario will be faced by each and every iOS Developer shortly.

Developer
  • 6,375
  • 12
  • 58
  • 92

1 Answers1

1

It seems like you want to keep the aspect ratio: i.e. 210x30 on an iPhone 5 screen with a width of 320, but approximately 246x35 on an iPhone 6 with a width of 375.

In Interface Builder, you can add an Aspect Ratio constraint. In code, you can add

    [NSLayoutConstraint constraintWithItem:self.label 
       attribute:NSLayoutAttributeHeight 
       relatedBy:NSLayoutRelationEqual 
       toItem:self.label 
       attribute:NSLayoutAttributeWidth 
       multiplier:210.0/30.0 
       constant:0];
jlw
  • 3,166
  • 1
  • 19
  • 24
  • I set the aspect ratio constraint in Interface Builder and it worked! Thanks! Accepted and Voted Up! Enjoy! :-) – Developer Sep 25 '14 at 05:35