Creating a string with custom kerning

suggest change

NSAttributedString, and its mutable subclass NSMutableAttributedString, can change how a string is drawn.

One use is custom kerning (letter spacing). label below is a UILabel. The range starts at character 6 and covers the 7 letters in “kerning”.

Swift

let attributedString = NSMutableAttributedString(string: "Apply kerning")
attributedString.addAttribute(NSKernAttributeName, value: 5, range: NSMakeRange(6, 7))
label.attributedText = attributedString

Objective-C

NSMutableAttributedString *attributedString;
attributedString = [[NSMutableAttributedString alloc] initWithString:@"Apply kerning"];
[attributedString addAttribute:NSKernAttributeName value:@5 range:NSMakeRange(6, 7)];
[label setAttributedText:attributedString];

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents