Why does UIButton resize when I access titleLabel property?

后端 未结 2 355
心在旅途
心在旅途 2021-01-28 21:46

I\'m trying to adjust the size of a button to (it\'s intrinsic size + a little bit more) in order to draw a custom background. However, every time I access self.titleLabel withi

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-28 22:24

    This isn't a bug, it's a consequence of auto layout. When using auto layout, you shouldn't set any frames. Instead, you should change the size or position by modifying the constraints. What's happening, is that whenever the view needs to be redrawn, the frame reverts to the frame that's defined by the constraints.

提交回复
热议问题