UILabel sizeToFit method not working properly

后端 未结 6 1051
梦如初夏
梦如初夏 2021-01-01 11:52

I\'m trying to show a long chunk of text inside a UILabel in one line. The UILabel is a subview of UIScrollView so I can scroll and see the entire UILabel.

My proble

6条回答
  •  春和景丽
    2021-01-01 12:24

    The most common reason for sizeToFit not working properly is the UILabel not having any autolayout constraints, for instance if you're implicitly relying on the view position remaining fixed relative to the top left. Adding any constraint at all (leading, top, centerY, anything) will fix it, presumably because it will result in layoutSubviews being called at some point, as suggested in Maxthon Chan's answer.

提交回复
热议问题