Skip to content

Instantly share code, notes, and snippets.

@fabiogiolito
Created December 11, 2018 12:14
Show Gist options
  • Save fabiogiolito/f63226c2a3d10026ef5d7992df43ed1b to your computer and use it in GitHub Desktop.
Save fabiogiolito/f63226c2a3d10026ef5d7992df43ed1b to your computer and use it in GitHub Desktop.
extension UILabel {
func setLineSpacing(lineSpacing: CGFloat) {
let text = self.text
if let text = text {
let attributeString = NSMutableAttributedString(string: text)
let style = NSMutableParagraphStyle()
style.lineSpacing = lineSpacing
style.alignment = self.textAlignment
attributeString.addAttribute(NSAttributedString.Key.paragraphStyle, value: style, range: NSMakeRange(0, text.count))
self.attributedText = attributeString
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment