Force text to be embedded vertically in UILabel?

I know that there are many threads similar to this, but I read them all (as far as I can tell) and did not see the same problem as mine.

I am trying to get all the text that will be displayed in the VERTICAL label.

Let me explain - Fonts are not always created the same way, therefore, although their overall height may be the same (for example, 24pts). However, Ascender and Descender vary widely - one font can be mostly above the baseline, and the other is mostly lower. Therefore, the same text with different fonts may not always be displayed in the same view / label.

For example, see the screenshots below.

The first is Helvetica-Bold 300pts. The second is Apple Gothic 300pts.

Note that the bottom of the "g" is disabled using Helvetica (and many other fonts too - try it, you'll see).

Helvetica-bold300

Apple gothic

So my problem is this: I would like to see all the text, regardless of the font. If the text in the Helvetica example can be moved up (and centered) inside the label, this will solve my problem. To make it easier, I only need to display one line.

Unfortunately, none of the solutions I've seen include downstream and upstream fonts and figure out how to draw text in Rect and not crop it. Please note that VerticalAlignment solutions in different threads do not resolve this issue.

Does anyone have any ideas or solutions for this?

+5
source share
1 answer

UILabel NSString - (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode, NSString UIKit.

- (void)setFont , , rect, , , .

+2

All Articles