美文网首页
iOS开发 给Label加下划线、中划线

iOS开发 给Label加下划线、中划线

作者: 小小Q吖 | 来源:发表于2016-06-01 09:21 被阅读283次
    1975627-b290ef9c1a340919.png

    下面直接上代码了

    添加中划线:

    UILabel *strikeLabel = [[UILabel alloc]initWithFrame:(CGRectMake(10,10,50,30))]; NSString *textStr =[NSString stringWithFormat:@"%@元",primeCost]; //中划线 NSDictionary *attribtDic =@{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]}; NSMutableAttributedString *attribtStr =[[NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic]; //赋值 strikeLabel.attributedText = attribtStr; [self.view addSubview:strikeLabel];

    添加下划线

    UILabel *underlineLabel =[[UILabel alloc]initWithFrame:(CGRectMake(10,10,50,30))]; NSString *textStr =[NSStringWithFormat:@"%@元",primeCost]; //下划线 NSDictionary *attirbtDic =@{NSUnderlineStyleAttributedString alloc]initWithString:textStr attributes:attribtDic]; //赋值 underlineLabel.attributedText = attribtStr; [self.view addSubview:underlineLabel];

    效果如图所示:

    1975627-7dfcab97f92a7872.png

    相关文章

      网友评论

          本文标题:iOS开发 给Label加下划线、中划线

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