0

私は文字列を持っています....別の色でShare Pictures表示したい.以前は文字列のその部分の色を変更していました.しかし、次の文字列を使用して設定しているときは機能しません.他の方法これを行う?ShareNSMutableAttributedStringcell.textLabel.text

この方法では機能しません。

NSMutableAttributedString *string3 = [[NSMutableAttributedString alloc]initWithString:@"Share pictures "];
[string3 addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, 4)];
NSString *tempStr3 = @"with your friends.";
NSString *finalString3 = [NSString stringWithFormat:@"%@%@" , string3, tempStr3];
[menuTextArray addObject:finalString3];

そしてテーブルビューのデータソースメソッドで。

 cell.textLabel.text = [menuTextArray objectAtIndex:indexPath.row];
4

3 に答える 3

2

あなただけに追加する必要がありNSMutableAttributedStringますmenuTextArray

NSMutableAttributedString *yourString = [[NSMutableAttributedString alloc]initWithString:@"Share pictures with your friends"];
[yourString addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, 4)];
[menuTextArray addObject:yourString];

次に設定しますattributedText

cell.textLabel.attributedText = [menuTextArray objectAtIndex:indexPath.row];
于 2013-12-26T09:45:03.810 に答える
1

attributedTextの代わりに使用text

cell.textLabel.attributedText = [menuTextArray objectAtIndex:indexPath.row];
于 2013-12-26T09:38:36.760 に答える