4

I have the following code which works flawlessly in iOS 6, problem is it has no effect whatsoever in iOS 7. How do I apply kerning and line spacing in iOS 7?

+ (NSAttributedString *)attributedText:(NSString *)text inFont:(UIFont *)font {
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];

    NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
    style.lineSpacing = 5;
    CGFloat kernSize = -0.6;
    [attributedString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)];
    [attributedString addAttribute:NSKernAttributeName value:@(kernSize) range:NSMakeRange(0, text.length)];

    return attributedString;
}
ifeins
  • 869
  • 1
  • 9
  • 20
  • How do you know it has no effect? Are you taking the return value and assigning it to a UILabel to actually see the result? How are you creating your UILabel and what are its properties? – Holly Oct 20 '13 at 05:13
  • I'm using code nearly identical to what you posted, and getting kerning and spacing fine in iOS 7. Your issue is not in the code you posted. – Aaron Brager Oct 30 '13 at 21:46
  • If anyone needs a solution, check it here: http://stackoverflow.com/a/35156265/4173671 – Arben Pnishi Feb 03 '16 at 14:20

1 Answers1

0

Maybe a duplicate to Why Does Kerning fail for NSAttributedString in IOS7

For some strange reason it does not work with the font Courier (in iOS7!) but with CourierNewPSMT.

Maybe try with different fonts.... here is a nice list of fonts on the iphone: http://iosfonts.com/

Community
  • 1
  • 1
naeger
  • 410
  • 3
  • 17