0

我怎樣才能在iOS的5.1這樣的 -的iOS attributedText 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在使用DTCoreText的向後兼容ATTR 5.1

+1

可能是這個 - https://github.com/AliSoftware/OHAttributedLabel ??? – Nubaslon

+0

** [This may help you。](http://stackoverflow.com/questions/3586871/bold-non-bold-text-in-a-single-uilabel)** – Hemang

回答

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降低!

0

看? ibuted字符串和HTMLish處理。