Adjust UILabel height depending on the text

前端 未结 30 1797
走了就别回头了
走了就别回头了 2020-11-22 03:53

Consider I have the following text in a UILabel (a long line of dynamic text):

Since the alien army vastly outnumbers the team, players m

30条回答
  •  遇见更好的自我
    2020-11-22 04:26

    Instead doing this programmatically, you can do this in Storyboard/XIB while designing.

    • Set UIlabel's number of lines property to 0 in attribute inspector.
    • Then set width constraint/(or) leading and trailing constraint as per the requirement.
    • Then set height constraint with minimum value. Finally select the height constraint you added and in the size inspector the one next to attribute inspector, change the height constraint's relation from equal to - greater than.

提交回复
热议问题