UILabel height calculation

后端 未结 2 707
迷失自我
迷失自我 2021-01-15 15:53

I have UILabel that the text is dynamically change based on server data. Sometime the data is so long that make my UILabel become multiline. Is the

相关标签:
2条回答
  • 2021-01-15 16:09

    If you are using Autolayout then no need to calculate height, just add leading,top and trailing constraint, set number of line to 0 for that label and line break mode to word-wrap, it will automatically update its height.

    P.S. Add the bottom contraints too if there is any other control in nib after label.

    0 讨论(0)
  • 2021-01-15 16:14

    You can use this :

    var labelHeight : CGFloat
    labelHeight = theLabel.boundingHeightForFixedWidth(theLabel.bounds.width)
    

    Hope it help :)

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