关于UIButton使用富文本无法改变标题颜色
2018-12-25 本文已影响156人
xiaolongLee
UIButton用了富文本设置属性之后,只能用setAttributedTitle才能改变颜色。 如果只用常规的[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 是不起作用的。改变颜色的示例代码如下
// 选中时字体颜色
NSDictionary *attrDict = @{NSForegroundColorAttributeName :"这里设置选中时文字颜色"};
NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:"设置的文字" attributes:attrDict];
[btn setAttributedTitle:attrStr forState:UIControlStateNormal];