我有字典数组
[
{
"price": 0,
"test_name": "Multislice CT Scan Virtual Bronchoscopy"
},
{
"price": 0,
"test_name": "Multislice CT Scan Dental"
},
{
"price": 0,
"test_name": "Multislice CT Scan Joint (3D)"
},
{
"price": 0,
"test_name": "Multislice CT Scan Lumbar"
},
{
"price": 0,
"test_name": "Multislice CT Scan Spine - Cervical / Thoracic"
},
{
"price": 0,
"test_name": "Multislice CT Scan CT Urography"
}
]
我正在将这个 Dictionary
数组转换为 NSString
,就像在每个字典值的末尾附加\n 一样
Multislice CT Scan Virtual Bronchoscopy
Rs.0
Multislice CT Scan Dental
Rs.0
Multislice CT Scan Joint (3D)
Rs.0
Multislice CT Scan Lumbar
Rs.0
Multislice CT Scan Spine - Cervical / Thoracic
Rs.0
Multislice CT Scan CT Urography
Rs.0
Multislice CT Scan (Arterial + Portal + Venous)
Rs.0
Multislice CT Scan Abdomen Triphasic Lever
Rs.0
现在我想要红色的 Rs.0 字符串...如何为该特定字符串赋予红色???
我正在使用静态表..因为我将整个字符串分配给单个标签..
最佳答案
您可以在 iOS 6 及更高版本中使用 NSMutableAttributedString。
示例代码:
NSString *strFirst = @"Multislice CT Scan Virtual Bronchoscopy";
NSString *strSecond = @"Rs.0";
NSString *strComplete = [NSString stringWithFormat:@"%@\n %@",strFirst,strSecond];
NSMutableAttributedString *attributedString =[[NSMutableAttributedString alloc] initWithString:strComplete];
[attributedString addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:[strComplete rangeOfString:strSecond]];
cell.textLabel.attributedText = attributedString;
关于ios - 如何将 UIcolor 分配给 NSString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37893776/