Reputation: 295
I used the solution here (UILabel sizeToFit doesn't work with autolayout ios6) to get the UILabel to fit the text.
However, when I increased my font size, the height did not fit any more.
I am not familiar with typography, but I guess the padding within the bounding box of the text always exists, and it is just not obvious when font size is small.
In my project, the text in the UILabel switches between two fonts, and the difference of padding makes it so hard to align it with other controls on the same view.
So my question is, how can I get rid of the padding-top and padding-bottom in a UILabel with large font-size?
Upvotes: 0
Views: 295
Reputation: 1319
Simply, you can't.
But you can decrease the Height
accordingly as font increases using following formula,
Int heightToDecrease = FontSize - 12; //Change the value to fit your font family.
lblText.frame = CGRectMake(lblText.frame.origion.x, lblText.frame.origion.y, lblText.frame.size.width, lblText.frame.size.height - heightToDecrease);
I know this is not the perfect solution but it will help you for sure.
Upvotes: -1