Why my UILabel 's AutoLayout not working

1.3k views Asked by At
  1. in storyboard I set view controller size iPhone3.5-inch
  2. add constraints with UILabel

enter image description hereenter image description here

  1. UILabel.text cannot show all,so i change view controller size iPhone 4.7-inch enter image description here

  2. so i tap UIlabel update frame , autolayout work, it all ok!this is iPhone 4.7-inchenter image description here

  3. now the problem coming,when i run in iPhone simulator iPhone 6, autolayout don't working, the label size only zoom, the width don't change longer。 and The following three images constraints width and height both 32,but in simulator iPhone 6 images size Look bigger,Why is this so? please help me ,very thinks enter image description here

  4. No matter iphone6 or iphone5 iphon6+ ,code here output 320, why...

    -(void)viewDidLayoutSubviews{ [super viewDidLayoutSubviews]; NSLog(@"%f",self.view.frame.size.width); }

2

There are 2 answers

0
Doro On
  1. Don't you forget to set constraints for your arrow image?

Set trailing and top constraint with fixed height/width.

  1. Set 'Autoshrink' property of your label to 'Fixed font size'

this prevents label from changing font size depend on it's frame

  1. Recreate your constraint for images - it looks like it pins to superview, so in runtime it scales to the size of superview

enter image description here

Hope this helps.

0
Dhaivat Vyas On

As per your question if you want text should not display ... then all you need to do is set number of lines = 0 and set Line break mode to word wrap.

As you are working with label it does not require any height constraint.

If you are building your application with size class and using launchScreen.xib then you label won't zoom and if you are using launch image then you need to all splash screen image of exact size.

You can find out about size of splash screen in below url.

https://stackoverflow.com/a/26191308/4101371

I've added images of view with constraint and changes in properties of label.

enter image description here

enter image description here

result will be displayed similarly in device and simulator. enter image description here

And if you don't want to display label in multiple lines then you can set Auto Shrink (Minimum font Size/ Minimum Font Scale)

Hope it will help you in solving your problem.