I have a label Like,
I want to display this single label with different font colors.
i.e..,
"First" string should be in redcolor.
"&" text should be roundcornerd and lightgraycolor.
I have a label Like,
I want to display this single label with different font colors.
i.e..,
"First" string should be in redcolor.
"&" text should be roundcornerd and lightgraycolor.
Use nsattributedstring https://developer.apple.com/reference/foundation/nsattributedstring
Example use How do you use NSAttributedString?
try this
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:singlestoreNode.objSeName];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,2)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(2,3)];
yourlable.attributedText = string;
yourlable.layer.cornerRadius = 8.0;
You can achieve that by creating 3 labels.
Set the colors for the label like this:
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:lblTemp.text];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(5,6)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(11,5)];
lblTemp.attributedText = string;
For the round background in "&" you can do the following:
[yourUILabel sizeToFit];
yourUILabel.backgroundColor = [UIColor lightGrayColor];
yourUILabel.layer.masksToBounds = YES;
yourUILabel.layer.cornerRadius = yourUILabel.frame.size.width/2;
Then you just need to align everything.