修改UILable文本的属性

- (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;
    
}

效果如下:


修改UILable文本的属性_第1张图片
Screen Shot 2015-06-22 at 19.40.02.png

你可能感兴趣的:(修改UILable文本的属性)