resize superview after subviews change dynamically using autolayout

后端 未结 4 1661
难免孤独
难免孤独 2020-12-04 05:53

I cant for the love of god the the hang of this resizing superview.

I have a UIView *superview with 4 UILabels. 2 function as header for t

4条回答
  •  不知归路
    2020-12-04 06:15

    Use container views

    In the following example I have a 30x30 image, and the UILabel is smaller than the containing view with the placeholder text. I needed the containing view to be at least as big as the image, but it needed to grow to contain multi-line text.

    In visual format the inner container looks like this:

    H:|-(15.0)-[image(30.0)]-(15.0)-[label]-(15.0)-|
    V:|[image(30.0)]|
    V:|[label(>=30.0)]|
    

    Then, set the containing view to match the height of the label. Now the containing view will ride the size of the label.

    As @smileyborg pointed out in his answer, connecting the content rigidly to the superview informs the layout engine that the simple container view should cause it to grow.

    Yellow alignment rectangles

    If you want the yellow alignment rectangles add -UIViewShowAlignmentRects YES in your scheme's list of run arguments.

    UILabel that is multi-line

提交回复
热议问题