我正在尝试将NSBackgroundColorAttributeName
属性设置为TTTAttributedLabel
,OHAttributedLabel
或SETextView
,但它不起作用。有人知道吗?示例代码如下。
class ViewController: UIViewController {
@IBOutlet weak var textLabel: UILabel!
@IBOutlet weak var ttLabel: TTTAttributedLabel!
@IBOutlet weak var ohLabel: OHAttributedLabel!
@IBOutlet weak var seTextView: SETextView!
override func viewDidLoad() {
super.viewDidLoad()
var content: String = "This is Test."
var text = NSMutableAttributedString(string: content)
text.addAttribute(NSBackgroundColorAttributeName, value: UIColor.redColor(), range: NSMakeRange(0, text.length))
textLabel.attributedText = text // It's Work.
ohLabel.attributedText = text // It's not Work
seTextView.attributedText = text // It's not Work
// It's not Work as well
ttLabel.setText(content, afterInheritingLabelAttributesAndConfiguringWithBlock: {
(attributedString) -> NSMutableAttributedString! in
attributedString.addAttribute(NSBackgroundColorAttributeName, value: UIColor.redColor(), range: NSMakeRange(0, attributedString.length))
//attributedString.addAttribute(kTTTBackgroundFillColorAttributeName, value: UIColor.yellowColor(), range: NSMakeRange(1, 3))
return attributedString
})
}
}
另外,我可以NSForegroundColorAttributeName
在每一个上label
正确设置“”。