0

I have a scenario to change the color of single repeat characters '#' in a string just like as image shown below. I m using this code.

    let textTag = lblNewsTag.text
    let range = (textTag! as NSString).rangeOfString("#")
    let attributedString = NSMutableAttributedString(string:textTag!)
            attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor() , range: range)
    lblTag.attributedText = attributedString

enter image description here

Salman Ghumsani
  • 3,647
  • 2
  • 21
  • 34

0 Answers0