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];

    效果如下图:

  • 相关阅读:
    php解析XML的两种方法
    Windows下xampp搭配php环境以及mysql的设置和php连接Mysql数据库
    管道
    Ubuntu文件系统
    Ubuntu如何使用Vscode写C++代码
    Ubuntu如何百度云盘下载
    Debug程序的使用
    寄存器
    汇编指令
    汇编第二章_寄存器
  • 原文地址:https://www.cnblogs.com/Walking-Jin/p/5741525.html
Copyright © 2011-2022 走看看