zoukankan      html  css  js  c++  java
  • iOS 给NSString文字上添加横线 中间和下划线

    有时候我们需要给文字添加横线,有两种情况:

    第一种是贯穿中间的横线:

    横线的颜色和文字的颜色保持一致

     _oldPriceLabel.text = @"3500";
    _oldPriceLabel.textColor = [UIColor lightGrayColor];
    NSMutableAttributedString *newPrice = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%@",_oldPriceLabel.text]];
    [newPrice addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, newPrice.length)];
     _oldPriceLabel.attributedText = newPrice;

    效果如图:

    第二种是给文字添加下划线:

    代码如下:

    NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:@"忘记密码?"];
    NSRange titleRange = {0,[title length]};
    [title addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:titleRange];
    [_forgetBtn setAttributedTitle:title
                          forState:UIControlStateNormal];

    效果如下图:

  • 相关阅读:
    iOS UI调试神器,插件injection for Xcode使用方法
    iOS 开发笔记-Objective-C之KVC、KVO
    iOS 测试企业应用的分发
    iOS 阅读唐巧博客心得
    iOS 添加启动图片
    Xcode 常用命令
    iOS 开发笔记
    iOS 开发常用链接总结
    iOS
    iOS UI基础
  • 原文地址:https://www.cnblogs.com/Walking-Jin/p/5741525.html
Copyright © 2011-2022 走看看