Skip to content

Instantly share code, notes, and snippets.

@idrougge
Last active March 8, 2019 15:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idrougge/ed94ae33cac116a87f315f930bec6c19 to your computer and use it in GitHub Desktop.
Save idrougge/ed94ae33cac116a87f315f930bec6c19 to your computer and use it in GitHub Desktop.
Turn on hyphenation for UILabel
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