How to implement LineSpacing and Background color of text with a UILabel or UITextview

Viewed 1025

enter image description here

How to make one UILabel or UITextView to accomplish that in swift 3.

2 Answers

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

hello victor u can select textview as attributed,after that u can change textcolor , background color,and line spcing

from bellow image u get idea

Related