美文网首页iOS自我学习库
IOS 优惠价格添加删除线

IOS 优惠价格添加删除线

作者: 浪博恩 | 来源:发表于2017-11-16 16:22 被阅读292次

    做电商类的app时,会经常遇到打折的时候,而网上打折价格的lable的删除线千篇一律,其实IOS本自带的就有删除闲的功能,Demo如下

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

    numberPrice.text=@"199.0元";

    numberPrice.textColor=[UIColor grayColor];

    NSUInteger length = [numberPrice.text length];

    //添加删除线

    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:numberPrice.text];

    [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(2, length-2)];

    [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor grayColor] range:NSMakeRange(2, length-2)];

    [numberPrice setAttributedText:attri];

    相关文章

      网友评论

        本文标题:IOS 优惠价格添加删除线

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