【发布时间】:2013-12-31 07:15:33
【问题描述】:
我有一个字符串:
NSString *userInfo = @"James Johnson @james";
我要做的是加粗James Johnson 并保持@james 正常字体。
所以我尝试使用NSAttributedString,但为了完成该过程,我在某处做错了事。
这是我尝试过的:
NSString *user = @"James Johnson @james";
UIFont *fontLight = [UIFont fontWithName:@"HelveticaNeue-Light" size:14];
UIFont *fontBold = [UIFont fontWithName:@"HelveticaNeue-Bold" size:14];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:userInfo];
//TESTING WITH RANDOM PARTS OF THE STRIN
[string addAttribute:NSForegroundColorAttributeName value:fontLight range:NSMakeRange(0, 3)];
[string addAttribute:NSForegroundColorAttributeName value:fontBold range:NSMakeRange(3, 5)];
NSString *str = [string string];
cell.textLabel.text = str;
即使我走错了方向,有没有办法让这项工作顺利进行?
什么不工作
由于某种原因,0 - 3 范围内的字符不是浅字体...而是整个cell.textLabel.text 以某种方式加粗,并且不是我在 UIFont 中指定的字体大小 14。
【问题讨论】:
-
那么问题出在哪里?
-
@Virussmca 更新了问题
-
您必须将
attributedText设置为单元格标签。
标签: ios xcode uitableview xcode5