Layout Constraint Conflicts in Default Today Widget

前端 未结 2 1929
你的背包
你的背包 2021-01-12 16:27

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

相关标签:
2条回答
  • 2021-01-12 17:09

    In some of Apple's stock UIView subclasses, they are instantiated with a size of zero. You need to configure your NSLayoutConstraints 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.

    0 讨论(0)
  • 2021-01-12 17:09

    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.

    0 讨论(0)
提交回复
热议问题