设置同一Label内涵不同颜色字体

       UILabel * label = [[UILabel alloc]init];

        NSString * htmlString = @"<span style=\"font-family:Helvetica;font-size:15pt;color:#9DC216\">感谢使用 </span> <span style=\"font-family:Helvetica;font-size:15pt;color:#222332\">Uday 友电</span>";

        NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType} documentAttributes:nil error:nil];

        label.attributedText = attrStr;

        label.textAlignment = NSTextAlignmentCenter;

       [self.view addSubview:label];

posted @ 2016-04-23 17:16  前路弯弯  阅读(479)  评论(0)    收藏  举报