Last active
March 8, 2019 15:40
-
-
Save idrougge/ed94ae33cac116a87f315f930bec6c19 to your computer and use it in GitHub Desktop.
Turn on hyphenation for 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
extension UILabel { | |
func hyphenate() { | |
let paragraphStyle = NSMutableParagraphStyle() | |
let attstr = NSMutableAttributedString(attributedString: self.attributedText!) | |
paragraphStyle.hyphenationFactor = 1.0 | |
attstr.addAttribute(.paragraphStyle, value: paragraphStyle, range: NSRange(0..<attstr.length)) | |
self.attributedText = attstr | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment