Reputation: 2461
I want to update the title of an iOS UIButton
named cardButton, with the RED word mat.
Here is my code:
NSMutableAttributedString *mat = [card.contents mutableCopy];
NSInteger _stringLength=[mat length];
UIColor *color;
color = [UIColor redColor];
[mat addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, _stringLength)];
[cardButton setAttributedTitle: mat forState:UIControlStateNormal];
NSLog
returns the right word for the word mat.
I have the following error. I know there is a problem with memory management, but I don't know what.
-[__NSCFString addAttribute:value:range:]: unrecognized selector sent to instance 0x7177370
Thanks!
Upvotes: 1
Views: 287
Reputation: 9913
Replace
NSMutableAttributedString *mat = [card.contents mutableCopy];
with this :
NSMutableAttributedString *mat = [[NSMutableAttributedString alloc] initWithString:[card.contents mutableCopy]];
Upvotes: 4