I am developing an iPhone app, and I want to set kerning in UILabel. The code I\'ve written (possibly around kCTKernAttributeName) seems to be in error. How mig
Swift 4 and 5
extension NSAttributedString {
/// Returns a new instance of NSAttributedString with same contents and attributes with kerning added.
/// - Parameter kerning: a kerning you want to assign to the text.
/// - Returns: a new instance of NSAttributedString with given kerning.
func withKerning(_ kerning: CGFloat) -> NSAttributedString {
let attributedString = NSMutableAttributedString(attributedString: self)
attributedString.addAttributes([.kern: kerning],
range: NSRange(location: 0, length: string.count))
return NSAttributedString(attributedString: attributedString)
}
]