Adjust letter spacing in iOS 7

You can adjust letter spacing like this, using NSAttributedString.

In Objective-C:

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"The Clash"];
[attributedString addAttribute:NSKernAttributeName
                         value:@(1.4)
                         range:NSMakeRange(0, 9)];
    
self.label.attributedText = attributedString;

In Swift 3:

let attributedString = NSMutableAttributedString(string: "The Clash")
attributedString.addAttribute(NSKernAttributeName, value: CGFloat(1.4), range: NSRange(location: 0, length: 9))

label.attributedText = attributedString

In Swift 4 and later:

label.attributedText = NSAttributedString(string: "The Clash", attributes: [.kern: 1.4])

More info on kerning is available in Typographical Concepts from the Text Programming Guide.

I don’t think there’s a TextKit feature that will automatically match font spacing between bold and regular text.

Leave a Comment