iphone - 字体颜色疑惑

标签 iphone ios nsstring uicolor core-text

我有这段代码可以将 DB(sqlite) 文本设置到我的 View 中。我只是使用核心文本在 View 中绘制文本。

NSMutableString *combined = [NSMutableString 字符串];

for(NSUInteger idx = 0; idx < [delegatee.allSelectedVerseEnglish count]; idx++) {
    [combined appendFormat:@"  %d %@", 
     idx + 1, 
     [delegatee.allSelectedVerseEnglish objectAtIndex:idx]];
}

self.multiPageView.text =combined;

delegatee.allSelectedVerseEnglish 这是数组...在文本的每个句子之间我放了这样的数字 1 haii this is nipin 2 haii this is stack overflow 3 etc etc..like that..i am able to change所有文本的文本颜色都包括数字..但我需要将“红色”颜色添加到数字上。如何更改上面代码中数字的颜色。这可能吗? 提前致谢。

最佳答案

您需要使用 NSMutableAttributedString 并使用 setAttributes:range: method 设置 NSForegroundColorAttributeName 值.

关于iphone - 字体颜色疑惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10372817/

相关文章:

ios - 通知 UITableView dataSource 的变化

iphone - 在 Objective C 中需要多重继承

ios - 当文本有多行时,在UILabel中查找属性文本的宽度

c# - 如何更改 android 和 ios 中开关的颜色?

iphone - 验证以 # 符号开头的 NSString

iphone - 使用 NSDataDetector 检查电子邮件

iphone - UITextView TextView :shouldChangeTextInRange:replacementText: doesn't fire when deleting large portions of text?

ios - UIPickerView 作为多个 UITextField 的 inputView

ios - 使用变量时NSString中的“Expression myExpression未使用”

ios - 将 base 64 转换为 NSString