Creating a string with custom kerning
suggest changeNSAttributedString, 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];
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents