3

enter image description here

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

Krunal
  • 77,632
  • 48
  • 245
  • 261
victor
  • 31
  • 5

2 Answers2

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

from bellow image u get idea

pradip rathod
  • 348
  • 3
  • 20