Skip to content

Instantly share code, notes, and snippets.

@michaelevensen
Last active January 16, 2018 18:03
Show Gist options
  • Save michaelevensen/fdeb00e408b6e96a5bdb13e4b6b4fceb to your computer and use it in GitHub Desktop.
Save michaelevensen/fdeb00e408b6e96a5bdb13e4b6b4fceb to your computer and use it in GitHub Desktop.
Adds a kerning property to UILabel.
import UIKit
@IBDesignable
class KerningLabel: UILabel {
@IBInspectable var kerning: CGFloat = 0.0 {
didSet {
if attributedText?.length == nil { return }
let attrStr = NSMutableAttributedString(attributedString: attributedText!)
let range = NSMakeRange(0, attributedText!.length)
attrStr.addAttributes([NSAttributedStringKey.kern: kerning], range: range)
attributedText = attrStr
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment