iOS 5/6 vs iOS 7 multiline label line spacing

efpies picture efpies · Sep 23, 2013 · Viewed 11.6k times · Source

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

Answer

Leo Natan picture Leo Natan · Sep 23, 2013
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 */
}