iOS使用NSMutableAttributedString 实

2017-11-16  本文已影响7人  羊妞麻麻
 /** 文字显示 */
    paragraphStr = [[NSMutableAttributedString alloc] init];
    NSMutableAttributedString *strName0 = [[NSMutableAttributedString alloc]initWithString:@"去"];
    [strName0 addAttribute:NSForegroundColorAttributeName value:[SQColorDefine color:SQColorGray010] range:NSMakeRange(0, 1)];
    [strName0 addAttribute:NSFontAttributeName value:[SQFontDefine font:SQFontBoldSize16] range:NSMakeRange(0, 1)];
    
    NSMutableAttributedString *strName1 = [[NSMutableAttributedString alloc]initWithString:@"偷"];
    [strName1 addAttribute:NSForegroundColorAttributeName value:[SQColorDefine color:SQColorRed008] range:NSMakeRange(0, 1)];
    [strName1 addAttribute:NSFontAttributeName value:[SQFontDefine font:SQFontBoldSize19] range:NSMakeRange(0, 1)];
    
    NSMutableAttributedString *strName2 = [[NSMutableAttributedString alloc]initWithString:@"邻居的卡"];
    [strName2 addAttribute:NSForegroundColorAttributeName value:[SQColorDefine color:SQColorGray010] range:NSMakeRange(0, 4)];
    [strName2 addAttribute:NSFontAttributeName value:[SQFontDefine font:SQFontBoldSize16] range:NSMakeRange(0, 4)];
    
    [paragraphStr appendAttributedString:strName0];
    [paragraphStr appendAttributedString:strName1];
    [paragraphStr appendAttributedString:strName2];
    
    titileLabel = [[UILabel alloc]init];
    [titileLabel setFont:[SQFontDefine font:SQFontPingFangSize19]];
    [titileLabel setTextColor:[SQColorDefine color:SQColorGray010]];
    [titileLabel setAttributedText:paragraphStr];
    [yellowBackGroundView addSubview:titileLabel];

最终结果:


28325367-22B7-4100-87AC-075A953FA4FB.png
上一篇 下一篇

猜你喜欢

热点阅读