Last active
January 16, 2018 18:03
-
-
Save michaelevensen/fdeb00e408b6e96a5bdb13e4b6b4fceb to your computer and use it in GitHub Desktop.
Adds a kerning property to UILabel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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