Created by CyanHall.com
on 12/22/2020
, Last updated: 03/30/2021.
👉 Star me if it’s helpful.
From StackOverflow: How to Increase Line spacing in UILabel in Swift
👉 Star me if it’s helpful.
From Interface Builder
:Programmatically using Swift 4 and Swift 5
: extension NSAttributedString {
func withLineSpacing(_ spacing: CGFloat) -> NSAttributedString {
let attributedString = NSMutableAttributedString(attributedString: self)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = .byTruncatingTail
paragraphStyle.lineSpacing = spacing
attributedString.addAttribute(.paragraphStyle,
value: paragraphStyle,
range: NSRange(location: 0, length: string.count))
return NSAttributedString(attributedString: attributedString)
}
}
let example = NSAttributedString(string: "This is Line 1 \nLine 2 \nLine 3 ").withLineSpacing(15)
testLabel.attributedText = example
More