I'm having some search option in my app, which will highlight given word in UISearchBar
. Given word may occurs multiple time in label I need t highlight all those words. How it is possible, I have tried with some set of codes but It will highlight only one occurrence of that word, Here is my sample code:
var SearchAttributeText = "The"
let range = (TextValue as NSString).range(of: SearchAttributeText)
let attribute = NSMutableAttributedString.init(string: TextValue)
attribute.addAttribute(NSForegroundColorAttributeName, value: UIColor.red , range: range)
self.label.attributedText = attribute
Need to support with both Upper
and lower
cases. Word The
may occurs multiple time need to highlight all.