设定字符串字符的颜色

来源:互联网 发布:淘宝bug 编辑:程序博客网 时间:2024/05/22 11:55

NSString *title2=@"欢迎阅读《你好明天》声明";

    NSMutableAttributedString *att = [[NSMutableAttributedStringalloc]initWithString:title2];

    [att addAttribute:NSForegroundColorAttributeNamevalue:[UIColorblueColor] range:NSMakeRange(4,5)];

    UILabel *label = [[UILabelalloc] initWithFrame:CGRectMake(50,200, 250,30)];

    label.font = [UIFontsystemFontOfSize:14];

    label.text = title2;

    label.textColor = [UIColorlightGrayColor];

    label.attributedText = att;

    [self.viewaddSubview:label];

0 0