Vertically align text within a UILabel (Note : Using AutoLayout)

前端 未结 17 2656
忘掉有多难
忘掉有多难 2020-12-23 02:24

I am Copying the same Question asked Before Question. I have tried the solutions given and was not able to solve it since sizetofit was not effective when I

相关标签:
17条回答
  • 2020-12-23 02:53

    You can try if button [button setContentVerticalAlignment:UIControlContentVerticalAlignmentTop];

    Edit :

    You can try with this if you want to use label only:

    https://stackoverflow.com/a/11278660/1223897

    0 讨论(0)
  • 2020-12-23 02:54

    You would do that by removing the minimum height.

    If you need the minimum height to something else below the label then you would use a container view that resized based on the label contents but used a minimum.

    0 讨论(0)
  • 2020-12-23 02:54

    I had a similiar issue where there were 3 labels. The middle label could have much longer text than the other two, so its height could grow much larger.

    Like this:

    I set the middle label's bottom space constraint to be >= the bottom label.

    That solved my problem.

    0 讨论(0)
  • 2020-12-23 02:59

    You can use UITextView instead of UILabel:
    Uncheck "Scrolling enabled"
    Uncheck "Editable"
    Uncheck "Selectable"
    Set background color to ClearColor

    0 讨论(0)
  • 2020-12-23 03:01

    I had the same problem, and this is how I solved it. I just edited the Baseline under Attribute Inspector for the Label. Set it to "Align Centers".

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