- (IBAction)buttonPressed:(UIButton *)sender {
NSString *title = [sender titleForState:UIControlStateNormal];
NSString *plainText = [NSString stringWithFormat:@"%@ button pressed.", title];
//_statusLabel.text = plainText;
//[sender setTitle:@"click!" forState:UIControlStateHighlighted];
NSMutableAttributedString *styledText = [[NSMutableAttributedString alloc] initWithString:plainText];
NSDictionary *attributes =
@{
//字体加粗
NSFontAttributeName: [UIFont boldSystemFontOfSize:_statusLabel.font.pointSize],
//字体颜色改为红色
//NSForegroundColorAttributeName: [UIColor redColor]
};
NSRange nameRange = [plainText rangeOfString:title];
[styledText setAttributes:attributes range:nameRange];
_statusLabel.attributedText = styledText;
}
效果如下: