iOS 给UILabel文字加下划线

摘自:http://blog.sina.com.cn/s/blog_6cd380c10101b6hn.html

 

//带下划线的“注” NSMutableAttributedString可变的属性字符串,添加下划线属性

 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, 300, 100)];

    label.backgroundColor = [UIColor redColor];
    label.numberOfLines = 3;

    label.adjustsFontSizeToFitWidth = YES;


    NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"

@"注:本工具测试结果为一周内平均每天盐的摄入量;问题中涉及的食物均以一人份为准;本软件更适用于成人;建议您及您的家人使用低钠盐"

"]];
    NSRange contentRange = {0,[content length]};
    [content addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
    
    label.attributedText = content;
    [self.view addSubview:label];

posted @ 2016-02-29 16:43  偶阵雨ss33  Views(371)  Comments(0Edit  收藏  举报