1

I am using TTTAttributedLabel and need to set background color. I can set text color like this.

    [mutableAttributedString addAttribute:NSForegroundColorAttributeName
                 value:color
                 range:range];
    self.lblContent.attributedText = mutableAttributedString;

But it is not working for background color.

    [mutableAttributedString addAttribute:NSBackgroundColorAttributeName
                 value:color
                 range:range];
    self.lblContent.attributedText = mutableAttributedString;

May I know what is wrong?

Khant Thu Linn
  • 5,905
  • 7
  • 52
  • 120

1 Answers1

0

You should use kTTTBackgroundFillColorAttributeName. See TTTAttributedLabel.h for details on that constant and several other attribute constants that are specific to TTTAttributedLabel.

Jonathan Hersh
  • 1,073
  • 1
  • 8
  • 15
  • also the value needs to be a CGColor, eg: mutableAttrString.addAttribute(kTTTBackgroundFillColorAttributeName, value: UIColor.yellowColor().CGColor, range: result.range) – bpn Sep 24 '15 at 21:46