1
我想用RED字mat更新名为cardButton的iOS UIButton
的标题。无法更改iOS中的按钮标题样式:attributes字符串
这里是我的代码:
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
返回字垫正确的字。 我有以下错误。我知道内存管理存在问题,但我不知道是什么。
-[__NSCFString addAttribute:value:range:]: unrecognized selector sent to instance 0x7177370
谢谢!
的NSLog的_stringLength? –
'card.contents'是什么类型?我猜,它不是'NSMutableAttributedString',因此'mat'既不是。 – Matthias
是的!接得好! Thx – Gabriel