I have observed a very strange behavior regarding Autolayout in the Today Widget I just created for my app. Trying to get to the root of the problem I ended up creating a pl
In some of Apple's stock UIView
subclasses, they are instantiated with a size of zero. You need to configure your NSLayoutConstraint
s so that they can properly react to this initial size. In the past, I've made top or bottom constraints an inequality so that the rest of the constraints may size themselves correctly and not break the layout.
Ex: Make your bottom constraint (<NSLayoutConstraint:0x15c666bd0 V:[UILabel:0x15c6617c0'Hello World']-(NSSpace(8))-[_UILayoutGuide:0x15c666380]>
) a LessThanOrEqualTo
with a constant
value of 8.0
.
The way that I've found helpful is to constrain a view on the top and the bottom, center it horizontally, and constrain the width. This has given me good results on the today widgets that I've worked on.