修改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;
    
}

效果如下:


Screen Shot 2015-06-22 at 19.40.02.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容