【发布时间】:2015-10-20 07:08:52
【问题描述】:
我在我的代码中使用属性字符串。为某些特定范围设置文本的字体和颜色。
为此,我使用下面的代码。
字体适用于范围,但未为该范围设置颜色。 NSForegroundColorAttributeName可能有问题。
如果有人有解决方案,请告诉我。
NSDictionary *attrs = @{ NSFontAttributeName:[UIFont systemFontOfSize:12.0f],NSForegroundColorAttributeName : [UIColor redColor] };
NSMutableAttributedString *titleStr = [[NSMutableAttributedString alloc]initWithString:@"New Message from Test"];
[titleStr addAttributes:attrs range:NSMakeRange(0, 3)];
【问题讨论】:
-
字体大小有效,但颜色无效。
-
我没有看到您的代码有任何问题。我刚刚使用了你的代码,它工作正常。 See here
-
@RamarajT 我测试了它,但它不起作用
-
你如何使用titleStr?您是否将其设置为任何 UILabel?您是否尝试过像我一样调试和悬停 titleStr?
-
我必须在标签上设置它。是的,我做到了。等等我分享截图
标签: ios objective-c nsstring nsattributedstring