Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILabel Font Clipping iOS

Tags:

ios

uilabel

fonts

I'm loading a font and setting it on a label like this

UIFont *font = [UIFont fontWithName:@"MyMonoFont" size:150.0];
label.font = font;
label.text = "TOBY"

However, it seems to clip or hide the bottom part of the text (as shown below). It works fine with another font I tried. Both fonts are TTF and are "valid" according to the "validate" action in Mac's Font Book app.

enter image description here

There are some constraints (it's auto layout) but as I say, anther font seems to cope ok.

Thanks for any hints.

EDIT: Bit of an update; updating the label frame size doesn't make a difference (if I have auto layout on). I'd like to keep auto layout on but suspect its clashing / resizing the frames. I wonder if theres a way for them to play nicely.

like image 989
Toby Avatar asked Jan 15 '23 03:01

Toby


2 Answers

Increase the height of frame of label according to font size of your label .

label.frame = your frame.
like image 148
abhishekkharwar Avatar answered Jan 28 '23 20:01

abhishekkharwar


Use the sizeToFit method of UILabel to achieve this.

[label sizeToFit];

or manually compute the label's size and set the label's frame Dynamically changing font size of UILabel

like image 36
sunkehappy Avatar answered Jan 28 '23 18:01

sunkehappy