How to make UILabel which adjusts the text in the upper left corner?

For some strange reason, this does not work on iPhone OS 3.0: I made a big full-screen UILabel with numberOfLines = 0 and baselineAdjustment = UIBaselineAdjustmentNone .

He refuses to display the text in the upper left. It is always in the center of the bounding box aligned to the left.

The documentation says:

UIBaselineAdjustmentNone Adjust text relative to the upper left corner of the bounding box. This is the default setting. Available on iPhone OS 2.0 and later.

Probably a structure error? I started with brilliant new labels to check it out. The text is centered.

+4
source share
1 answer

The default implementation vertically centers the text and does not preserve the contentMode property. Pull drawTextInRect: into a subclass.

 @implementation TopLeftLabel -(void) drawTextInRect:(CGRect)inFrame { CGRect draw = [self textRectForBounds:inFrame limitedToNumberOfLines:[self numberOfLines]]; draw.origin = CGPointZero; [super drawTextInRect:draw]; } @end 

The baselineAdjustment property is performed strictly for when the font size is adjusted according to the width.

+10
source

Source: https://habr.com/ru/post/1310015/


All Articles