UILabel NSAttributedString interval ignored on iOS7

So basically I have a label with an attributed string that has its own line spacing. It works the same as on iOS6, but not on iOS7, where my spacing is a little less than the default, but even close to where it should be. Here is my code:

NSDictionary *textAttributes1 = @{ NSForegroundColorAttributeName: MUSTARD_TEXT, NSFontAttributeName:[BEBAS_FONT_DEFAULT_TO_SIZE20]};
NSMutableString *aux;
if(text)
      aux = [[NSMutableString alloc] initWithString:[text uppercaseString]];
else
      aux = [[NSMutableString alloc] initWithString:@"YES"];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:aux];
[str addAttributes:textAttributes1 range:NSMakeRange(0, [aux length])];

NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init];
[paragrahStyle setLineSpacing:-7];
[paragrahStyle setMaximumLineHeight:26];
[str addAttribute:NSParagraphStyleAttributeName value:paragrahStyle range:NSMakeRange(0, [aux length])];

[_label setAttributedText:str];

And the shortcut looks like this:

    _label = [[UILabel alloc] init];
    _label.backgroundColor = [UIColor clearColor];
    _label.numberOfLines = 0;
    _label.lineBreakMode = NSLineBreakByWordWrapping;
    _label.preferredMaxLayoutWidth = 226;

The space between the lines should be like 2 px, which works fine on iOS6, but the space is huge on iOS7. Any ideas?

+4
source share

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


All Articles