我如何在iOS 5.1中制作这样的
NSString *statusStrColored = [NSString stringWithFormat:@"%@ (%@)", statusStr, paymentStatusStr];
NSLog(@"stoka = %@", statusStrColored);
//NSArray *components = [statusStrColored componentsSeparatedByString:@" "];
NSRange greenRange = [statusStrColored rangeOfString:statusStr];
NSRange redRange = [statusStrColored rangeOfString:paymentStatusStr];
NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:statusStrColored];
[attrString1 beginEditing];
[attrString1 addAttribute: (NSString*)kCTForegroundColorAttributeName
value:(id)[[UIColor greenColor] CGColor]
range:greenRange];
[attrString1 addAttribute: (NSString*)kCTForegroundColorAttributeName
value:(id)[[UIColor redColor] CGColor]
range:redRange];
[attrString1 endEditing];
cell.textLabel.attributedText = attrString1;
在iOS 6中它是可以的,但在5.1中…这不可用((
我有错误的代码-
cell.textLabel.attributedText = attrString1;
它可能在iOS 5.1中具有模拟功能吗?
看看使用DTCoreText进行向后兼容的属性字符串和HTMLish处理。
我把文本分成两个标签,然后这样做)-
cell.statusInfo.text = [NSString stringWithFormat:@"%@", statusStr];
UIColor *statusColor = (bronInfo.status == csConfirmed ) ? [UIColor greenColor] : [UIColor redColor];
cell.statusInfo.textColor = statusColor;
cell.paymentInfo.text = [NSString stringWithFormat:@"(%@)", paymentStatusStr];
UIColor *payColor = (bronInfo.paymentStatus == psPaid ) ? [UIColor greenColor] : [UIColor redColor];
cell.paymentInfo.textColor = payColor;
Сode减少!