如何使用UILabel或UITextview

时间:2017-10-03 09:28:53

标签: ios swift3 uilabel uitextview background-color

enter image description here

如何使一个UILabel或UITextView在swift 3中完成。

2 个答案:

答案 0 :(得分:0)

你好victor你可以选择textview作为归属,之后你可以改变textcolor,背景颜色和线条spcing

from bellow image u get idea

答案 1 :(得分:0)

此处带有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