0

I set inset constraints for 2 labels, and width is set to fixed value. number of lines is set to 0.

What I expect is the UILabels are resized to fit, and the parent view is also auto resized. But the output is the container remains the same size but the sub uilabels are either too high or too short. What's the problem? Thanks.

enter image description here

enter image description here

Here is the constraints

enter image description here

PeiSong
  • 905
  • 9
  • 16

2 Answers2

1

Try setting the content hugging priority to a higher value. This affects how resistant a view is to expanding past its intrinsic content size.

cobbal
  • 66,343
  • 18
  • 135
  • 154
  • @benxiong Maybe it's a problem with the multiline thing then. Would using the property from this answer fix it? http://stackoverflow.com/a/19777242/73681 – cobbal Jun 29 '14 at 06:59
  • I tried and not working. It seems that the priority of container is the topmost, so no matter what I do the frame of container never change but internal UILabels do. What I expect is UILabels resize first then container resize accordingly, how to make this happen? – PeiSong Jun 29 '14 at 23:13
  • @benxiong The labels should be able to influence the frame of the container. You can always check by assigning a height to them with a constraint and see if it is still ignored. – cobbal Jun 30 '14 at 03:32
1

The image of UILabel looks like it is truncating the contents. So if you want to display the text in the next line if it is bigger then you need to use the below api.

label.numberOfLines=0;
Hussain Shabbir
  • 13,963
  • 4
  • 34
  • 53