在我的应用程序中,我像这样在标签中显示文本
cell.lblUserDetails.text=[NSString stringWithFormat:@"%@ and %@ other likes your post", [dictionary valueForKey:@"username"], [dictionary valueForKey:@"CuriousCount"]];
在这里,我要突出显示Username和CuriousCount(以红色显示),并且username和CuriousCount也应该是可单击的。
最佳答案
UIColor *color = [UIColor redColor];
NSDictionary *attrs = @{ NSForegroundColorAttributeName : color };
NSAttributedString *nameStr = [[NSAttributedString alloc] initWithString:[dictionary valueForKey:@"username"] attributes:attrs];
NSAttributedString *countStr = [[NSAttributedString alloc] initWithString:[dictionary valueForKey:@"CuriousCount"] attributes:attrs];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] init];
[string appendAttributedString:nameStr];
[string appendAttributedString:[[NSAttributedString alloc] initWithString:@" and "]];
[string appendAttributedString:countStr];
[string appendAttributedString:[[NSAttributedString alloc] initWithString:@" other likes your post"]];
cell.lblUserDetails.attributedText = string;
关于ios - 在UILabel中突出显示特定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30122031/