Having trouble getting UIView sizeToFit to do anything meaningful

后端 未结 4 635
陌清茗
陌清茗 2020-12-09 02:07

When I add a subview to a UIView, or when I resize an existing subview, I would expect [view sizeToFit] and [view sizeThatFits] to ref

4条回答
  •  一向
    一向 (楼主)
    2020-12-09 02:36

    You can do some like that using IB alone (xcode 4.5):

    1. Click on the UIView
    2. in the Size inspector drag content hugging to 1 (both horizontal and vertical)
    3. drag compression resistance to 1000 (for both)
    4. under the UIView's constraints click on Width and change priority to 250
    5. Do the same for Height
    6. You can use the UIView's inset to control padding for left/right/top/bottom

提交回复
热议问题