Frage

How i can make in iOS 5.1 like this -

 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;

In iOS 6 its Ok, but in 5.1 ... this not available(((

And i have Error on code -

 cell.textLabel.attributedText = attrString1;

May it have analog in iOS 5.1?

War es hilfreich?

Lösung 2

I Broke the text into two Label, and do this )) -

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 is reduced!

Andere Tipps

Look at using DTCoreText for backwards compatible attributed string and HTMLish handling.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top