Reputation: 141
Below is the sample code to add a background colour of a attributed string but i want to set a lable attributed string colour to a image. Is there any way to do this?
let attributedString = NSMutableAttributedString(string:text!)
attributedString.addAttribute(NSAttributedStringKey.backgroundColor, value: UIColor.red , range: range)
Upvotes: 2
Views: 741
Reputation: 2615
You can simply use textColor
property of UILabel
label.textColor = UIColor(patternImage: UIImage(named:"Pattern.jpg")!)
Upvotes: 0
Reputation: 86
UIColor has a method called "patternImage" where we can set image
let attributedString = NSMutableAttributedString(string:text!)
attributedString.addAttribute(NSAttributedStringKey.backgroundColor, value: UIColor(patternImage: UIImage(named: "bg.png")!) , range: range)
label.attributedText = attributedString
Upvotes: 3
Reputation: 16416
You want to get label's attributed text and apply background color to UIImageView
You can fetch attributed text apply to label by label.attributedText
and from that you can get NSBackgroundColorAttributeName
and apply to you ImageView
Upvotes: 0