0

我怎么能像这样在 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 中具有模拟功能吗?

4

2 回答 2

0

我将文本分成两个标签,然后执行此操作))-

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 减少了!

于 2013-07-25T14:33:05.797 回答
0

查看使用DTCoreText进行向后兼容的属性字符串和 HTMLish 处理。

于 2013-07-25T13:19:27.457 回答