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

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

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

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

效果如图:

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

代码如下:

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

效果如下图:

iOS 给NSString文字上添加横线 中间和下划线的更多相关文章

  1. iOS 开发富文本之TTTAttributedLabel 在某个特定位置的文字添加跳转,下划线,修改字体大小,颜色

    @property(nonatomic , strong) TTTAttributedLabel * ttLabel; @property(nonatomic , strong) NSRange li ...

  2. iOS:如何实现在文字上添加拼音

    一.介绍 最近项目有一个需求,需要给朗诵的文字添加对应的拼音,而且要求使用原生的控件实现.一开始听到这个需求挺懵逼的,感觉有点难.后来,静下来想一下,其实还是可以实现的,无非就是自定义了.下面,就来说 ...

  3. IOS 在一个透明视图上添加不透明的子控件

    环境: 在一个透明的view中添加一个tableview,tableview也变透明了. 解决: 不要这样设置view的透明度 view.backgroundColor = [UIColor clea ...

  4. iOS tableview自定义cell上添加按钮实现删除功能

    在删除的时候,先删除数据源,再删除cell 但是,会发现一直崩: numberOfRowsInSection 解决方案:

  5. IOS中 如何去除Tabview里面cell之间的下划线

    可以利用Tabview的separatorStyle属性来设置,选择其中的UITableViewCellSeparatorStyleNone 即可去除cell之间的下划线 self.tableView ...

  6. 实现文字下划线 ---模拟text-decoration

    css 的text-decoration可以实现文字下方的下划线,但是距离文字比较近,不是很好看,我们可以使用border-bottom来模拟这个效果 (inline元素虽然不可以设置margin-t ...

  7. Inno Setup技巧[界面]欢迎页面上添加文字

    原文:Inno Setup技巧[界面]欢迎页面上添加文字 本文介绍在"欢迎页面添加文字"的两种方法. 界面预览: Setup技巧[界面]欢迎页面上添加文字" title= ...

  8. iOS实现类似QQ的好友列表,自由展开折叠(在原来TableView的基础上添加一个字典,一个Button)

    //直接代码 只包含 折叠展开字典的处理搭建#import "CFViewController.h" @interface CFViewController ()<UITab ...

  9. python 图片上添加文字

    import PIL from PIL import ImageFont from PIL import Image from PIL import ImageDraw #设置字体,如果没有,也可以不 ...

随机推荐

  1. ognl.OgnlException: target is null for setProperty(null, "emailTypeNo", [Ljava.lang.String;@1513fd0)

    [com.opensymphony.xwork2.ognl.OgnlValueStack] - Error setting expression 'emaiTypeDto.emailTypeNo' w ...

  2. 苹果微信input输入框被键盘遮挡

    最近一个项目,input输入框需要在页面的最下面(position:fixed),这样,当键盘获取焦点的时候, 苹果自带键盘不会挡住输入框,但是搜狗输入法的键盘就会挡住.可以用以下方法解决: docu ...

  3. [OC] 图片平铺

    Tip: self.bgImg.image = [self.bgImg.image resizableImageWithCapInsets:UIEdgeInsetsMake(100, 40, 40, ...

  4. [转]UE4 Blueprint编译过程

    Blueprint 编译概述   一.术语 Blueprint,像C++语言一下的,在游戏中使用前需要编译.当你在BP编辑器中,点击编译按钮时候,BP资源开始把属性和图例过程转换为一个类对象处理. 1 ...

  5. requirejs加载css样式表

    1. 在 https://github.com/guybedford/require-css 下载到require-css包 2. 把css.js或者css.min.js复制到项目的js目录下 3. ...

  6. LEfSe分析

    LEfSe软件用于发现两组或两组以上的biomarker,主要是通过非参数因子Kruskal-Wallis秩和检验来实现的.运行LEfSe软件主要分三大步骤:第一步:需要把普通的物种.基因等等的丰度信 ...

  7. SPOJ 375 Query on a tree 树链剖分模板

    第一次写树剖~ #include<iostream> #include<cstring> #include<cstdio> #define L(u) u<&l ...

  8. maven命令参考简要

    命令参考简要说明 mvn archetype:generate — 创建生成Tiny骨架工程 参数名 说明 groupId 用户项目的包目录,用户需要根据实际情况设置.比如com.abc artifa ...

  9. iOS静态库及Framework 创建

    本文转自cocoachina,尊重作者的汗水. 讲述的非常透彻,有需要的朋友可以阅读实践.转载请注明出处 //=================以下留着备份==================// 在 ...

  10. c++程序判断系统是Linux还是Windows

    用C++来实现,本来想了很多,后来越写越烂,而且结果总是不尽人意,干脆这样子好了: int main() { int judge = system("cls"); ) cout & ...