I'm trying to set NSBackgroundColorAttributeName
attribute on TTTAttributedLabel
, OHAttributedLabel
or SETextView
, but it's not work. Anyone have any idea? Sample code is followed.
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
})
}
}
In addition, I can set "NSForegroundColorAttributeName
" on every label
properly.