How to make one UILabel or UITextView to accomplish that in swift 3.
Asked
Active
Viewed 1,149 times
3
-
1Possible duplicate of [Set UILabel line spacing](https://stackoverflow.com/questions/3880526/set-uilabel-line-spacing) – Sandeep Bhandari Oct 03 '17 at 09:31
-
1NSAttributedString + NSBackgroundAttributeName + Line Spacing set to a higher value on potentially a NSParagraphStyle. – Larme Oct 03 '17 at 09:39
-
Have you managed to do it? – Pei May 08 '18 at 03:33
2 Answers
1
Here solution with Label.
let label = UILabel()
let stringValue = "How to implement LineSpacing and Background color of text with a UILabel"
let attrString = NSMutableAttributedString(string: stringValue)
var style = NSMutableParagraphStyle()
style.lineSpacing = 24 // change line spacing between paragraph like 36 or 48
style.minimumLineHeight = 20 // change line spacing between each line like 30 or 40
attrString.addAttribute(NSParagraphStyleAttributeName, value: style, range: NSRange(location: 0, length: stringValue.characters.count))
// background color
attrString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.red, range: NSRange(location: 0, length: stringValue.characters.count))
label.attributedText = attrString

Krunal
- 77,632
- 48
- 245
- 261
-1
hello victor u can select textview as attributed,after that u can change textcolor , background color,and line spcing

pradip rathod
- 348
- 3
- 20