UILabel text layout when packaging is “wrong” in iOS 7

The screenshot is shown in iOS 7. label1(yellow, top) is drawn with text appearing under the upper left edge of the frame and cropped from the bottom. In iOS 5/6, the beginning of the text is the upper left edge of the label frame. label2and label3rendering and layout as expected.

enter image description here

Here is the code to create this view:

- (void)loadView
{
    UIView *view = [[UIView alloc] initWithFrame:UIScreen.mainScreen.applicationFrame];
    view.backgroundColor = UIColor.blueColor;
    self.view = view;

    UILabel *label1 = [UILabel new];
    label1.backgroundColor = UIColor.yellowColor;
    label1.font = [UIFont systemFontOfSize:16.0f];
    label1.numberOfLines = 0;
    label1.lineBreakMode = NSLineBreakByWordWrapping;
    label1.frame = CGRectMake(50, 100, 200, 18);
    label1.text = @"This text is too long to fit on one line.";
    [self.view addSubview:label1];

    UILabel *label2 = [UILabel new];
    label2.backgroundColor = UIColor.greenColor;
    label2.font = [UIFont systemFontOfSize:16.0f];
    label2.numberOfLines = 0;
    label2.lineBreakMode = NSLineBreakByWordWrapping;
    label2.frame = CGRectMake(50, 150, 200, 36);
    label2.text = @"This text is too long to fit on one line.";
    [self.view addSubview:label2];

    UILabel *label3 = [UILabel new];
    label3.backgroundColor = UIColor.orangeColor;
    label3.font = [UIFont systemFontOfSize:16.0f];
    label3.numberOfLines = 0;
    label3.lineBreakMode = NSLineBreakByWordWrapping;
    label3.frame = CGRectMake(50, 200, 200, 18);
    label3.text = @"This text is short.";
    [self.view addSubview:label3];
}

QUESTION . Why is this different in iOS 7 and what properties of the label do I need to change so that the text in is label1displayed, starting from the upper left edge of its frame, as expected.

+4
source share
1 answer

. , , , , - , , .

. label1 18. 16 . iOS 5/6, -, , iOS 7 . , , , .

. , , . , , .

+8

All Articles