笔画基本上使用荧光笔代表了该文本部分的随意突出显示。
[我曾考虑过使用resizableImageWithCapInsets
,然后将其用作文本背景,但不适用于突出显示顶部和底部边缘的突出显示工件。
我的问题归结为:
我几乎可以通过使用SVG积分在Android上实现它,但是我找不到在iOS上实现它的方法。
借助属性字符串,您可以实现此目的。
样本代码
let s = "this is Highlight text" as NSString
var att = NSMutableAttributedString(string: s as String)
let r = s.range(of: "Highlight", options: .regularExpression, range: NSMakeRange(0,s.length))
if r.length > 0 {
att.addAttribute(NSAttributedString.Key.backgroundColor, value: UIColor.red, range: r)
}
someLabel.attributedText = att