嗨下面是我需要实现的视图UILabel.我听说过NSAttributedString但不确定如何使用它进行动态文本加载.

整个文本字体是Roboto-Light.但是,我必须从前两位医生的API响应中替换文本'Andrew Murphy博士,John Smith',并从API获得"23位医生"的计数,以便相应地调整此标签.您可以看到的文本颜色取决于文本是常量还是动态.我不知道如何实现它.因此,一些代码片段真的很受欢迎.
谢谢!
我在这篇文章中找到了NSAttributedString的例子.我的问题是 - 是否有任何提示,如何使用它UIRefreshControl class?
从上面的帖子:
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:@"firstsecondthird"];
[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)];
Run Code Online (Sandbox Code Playgroud)
属性是否UIRefreshControl自动调用?
编辑:
我知道如何设置它,我想知道它是否用于任何其他目的然后"只是"格式化标签 - 是否能够显示两个字符串的UIRefresherControl ?一个被拉出之前,一个被拉了之后?当我看到我不能放入"普通"字符串时,这就是我的想法.
我有一个UITableViewCell由两个单词组成的文本标签.
如何更改单词的颜色; 将第一个单词设为绿色,将第二个单词设为红色?
当使用下面的片段时,我得到了undefined / undeclared error开启
NSForegroundColorAttributeName
我的代码片段
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:self.myDisplayTxt];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];
Run Code Online (Sandbox Code Playgroud)
请告诉我
我想从IOS 5中的句子中更改特定单词的颜色.让我的字符串是
我想要更改密码'abc'的颜色.请帮我.NSString str = @"Your password is abc";
提前致谢.
有没有办法可以像往常一样将UIColor分配给NSString
cell.textLabel.text = [UIColor grayColor];
Run Code Online (Sandbox Code Playgroud)
我正在尝试为以下字符串添加颜色,如:
NSString *text = @"Hello"
[text setColor:[UIColor grayColor]; // It gives error here saying it cannot assign
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以为NSString分配颜色?
我想在textfield占位符文本中添加必填字段标记,如下图所示,请告诉我,我完全搞糊涂该怎么办

ios ×5
objective-c ×4
ios6 ×2
iphone ×2
uilabel ×2
cocoa-touch ×1
ios4 ×1
ios5 ×1
ios7 ×1
nsstring ×1
text-styling ×1
uicolor ×1
uitableview ×1
xcode4.2 ×1