jamesMcKey
jamesMcKey

Reputation: 491

How to change line spacing for text in UILabel swift

I have looked at solutions on stack and they have not helped me. The following is my attempt to change the line spacing for the text in my UILabel. Please can someone advise. I see no effect on my line spacing.

 let myText = abstractText.text!
 let myParagraphStyle = NSMutableParagraphStyle()
 myParagraphStyle.lineSpacing = 5

 let myNsAttrStringObject = NSAttributedString.init(string: myText, attributes: ["paragraphStyle":myParagraphStyle])
 abstractText.attributedText = myNsAttrStringObject

Upvotes: 1

Views: 1245

Answers (1)

Francesco Deliro
Francesco Deliro

Reputation: 3939

Your attribute key is not correct in this way, you can use objective-c key NSParagraphStyleAttributeName or swift 4 key NSAttributedStringKey.paragraphStyle:

let myNsAttrStringObject = NSAttributedString.init(string: myText, attributes: [NSParagraphStyleAttributeName: myParagraphStyle])

Upvotes: 3

Related Questions