美文网首页
Label显示不同颜色字体等的字符串

Label显示不同颜色字体等的字符串

作者: WTF丶程序猿 | 来源:发表于2017-12-14 16:12 被阅读0次

    UILabel*label = [[UILabelalloc]initWithFrame:CGRectMake(0,50,300,40)];

    [self.viewaddSubview:label];

    NSString*string =@"¥300   ¥322";

    NSString*subString =@"¥322";

    NSRangerange = [stringrangeOfString:subString];

    NSMutableAttributedString*attri = [[NSMutableAttributedStringalloc]initWithString:stringattributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleNone)}];

    [attriaddAttribute:NSStrikethroughStyleAttributeNamevalue:@(NSUnderlineStyleSingle)range:range];

    [attriaddAttribute:NSForegroundColorAttributeNamevalue:[UIColororangeColor]

    range:range];

    [attriaddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:20]

    range:range];

    label.attributedText= attri;

    相关文章

      网友评论

          本文标题:Label显示不同颜色字体等的字符串

          本文链接:https://www.haomeiwen.com/subject/oaiauttx.html