Adjust UILabel height depending on the text

前端 未结 30 2175
走了就别回头了
走了就别回头了 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:32

    Check this work perfectly without adding Single line of code. (Using Autolayout)

    I made a demo for you according to your requirement. Download it from below link,

    Autoresize UIView and UILabel

    Step by Step Guide :-

    Step 1 :- Set constrain to UIView

    1) Leading 2) Top 3) Trailing (From mainview)

    Step 2 :- Set constrain to Label 1

    1) Leading 2) Top 3) Trailing (From it's superview)

    Step 3 :- Set constrain to Label 2

    1) Leading 2) Trailing (From it's superview)

    Step 4 :- Most tricky give botton to UILabel from UIView .

    Step 5 :- (Optional) Set constrain to UIButton

    1) Leading 2) Bottom 3) Trailing 4) Fixed Height (From mainview)

    Output :-

    Note :- Make sure you have set Number of lines =0 in Label property.

    I hope this info enough to understand Autoresize UIView according to UILabel's height and Autoresize UILabel According to text.

提交回复
热议问题