iOS 5/6 vs iOS 7 multiline label line spacing
Asked Answered
G

2

10

I ran my app under iOS 7 and discovered that multiline labels (non-attributed, plain text) render with a small line spacing. Anyone knows what to do it with iOS 5 compatibility?

iOS 5/6

iOS 5/6

iOS 7

iOS 7

Griffon answered 23/9, 2013 at 17:39 Comment(1)
Did u get the solution?Curry
O
18
if(NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1)
{
    NSFont *font = /* set font */;

    NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    [paragraphStyle setLineSpacing: /* required line spacing */];

    NSDictionary *attributes = @{ NSFontAttributeName: font, NSParagraphStyleAttributeName: paragraphStyle };
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"strigil" attributes:attributes];

    [label setAttributedText: attributedString];
}
else
{
    /* old method */
}
Oaks answered 23/9, 2013 at 21:37 Comment(7)
if reducing linespacing to 0 'zero' is not sufficient, you should have a look to the "maximumLineHeight" property of the paragraphStyle.Tbilisi
@TwiterZX Reducing light height can create issue where some character colliding.Ezraezri
@Leo Natan I agree, this can produce an issue in text drawing if the maximumLineHeight is lower then the font lineheight.Tbilisi
@Leo Natan I used this to remove the font descender value as it is in uppercase, so for me in this case, it is safe. "maximumLineHeight = font.ascender".Tbilisi
@TwiterZX A letter like "Q" still has a descender, as well as other Unicode characters. But yeah, your comment should be considered as well.Ezraezri
Why NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; not showing any effect?Alchemist
@SahebSingh Because I assume alloc] init] doesn't return the default paragraph style.Ezraezri
P
1

I used MSLabel in iOS5/6. After iOS7 released, MSLabel is still working normally.

Nothing different in labels between iOS5/6 and iOS7. You can try MSLabel at https://github.com/LemonCake/MSLabel

Pucka answered 7/10, 2013 at 8:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.