下面是添加属性字符串背景颜色的示例代码,但我想为图像设置标签属性字符串颜色。有没有办法做到这一点?
let attributedString = NSMutableAttributedString(string:text!)
attributedString.addAttribute(NSAttributedStringKey.backgroundColor, value: UIColor.red , range: range)
UIColor 有一个名为“patternImage”的方法,我们可以在其中设置图像
let attributedString = NSMutableAttributedString(string:text!)
attributedString.addAttribute(NSAttributedStringKey.backgroundColor, value: UIColor(patternImage: UIImage(named: "bg.png")!) , range: range)
label.attributedText = attributedString
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句