Use autolayout to set dynamic UIView to match container view

前端 未结 2 1791
暖寄归人
暖寄归人 2020-12-13 06:32

I have a UIView in IB that has another UIView within it, which I am using as a container view. In code, I create three different views and then animate the appropriate one

2条回答
  •  悲&欢浪女
    2020-12-13 06:55

    In the problem you state "my new subviews are not scaled to match the container view" - but from the description I think they are - the problem is that your container view has no fixed size.

    I think that if you set your container view to have a fixed width and height that should do it, you may also need to call

    [self.containerView layoutSubviews]
    

    to force a resize after updating the constraints.

    I'd also suggest you swap to using the text based formatting, you could swap out your lines above for something like "H:|[newSubview]|" and "V:|[newSubview]|"

提交回复
热议问题