iOS开发 给Label加下划线、中划线
2017-04-06 10:06
281 查看
当我们在做一些购物类APP或者是商品展示类的APP时,我们经常会遇到某种商品打折优惠或者抢购的场景。并且为了吸引客户,商家一般把打折商品的现价和原价同时显示出来,进行对比,此时就出现了为展示原价的label添加中划线或者是下划线的需求。
我们参考一下驴妈妈的首页:
驴妈妈首页-中划线
下面就直接上代码了:
添加中划线:
[/code]
添加下划线:
[/code]
效果如图所示:
我们参考一下驴妈妈的首页:
驴妈妈首页-中划线
下面就直接上代码了:
添加中划线:
[code] 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];
[/code]
添加下划线:
[code] UILabel *underlineLabel = [[UILabel alloc] initWithFrame:(CGRectMake(10, 10, 50, 30))]; NSString *textStr = [NSString stringWithFormat:@"%@元", primeCost]; // 下划线 NSDictionary *attribtDic = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}; NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic]; //赋值 underlineLabel.attributedText = attribtStr; [self.view addSubview:underlineLabel];
[/code]
效果如图所示:
相关文章推荐
- iOS 分享新浪微博开发通知
- ios 开发环境 复制的另一台电脑
- <转> iOS开发网络篇—文件的上传
- iOS KVC和KVO开发模式
- IOS 开发,调用打电话,发短…
- ios开发 UITableCell 可重用问题
- iOS开发-调用google map并显…
- <转> iOS开发网络篇—大文件的…
- (转)IOS 开发调用打电话,发短信
- iOS开发- 蓝牙后台接收数据
- ios 第三方苹果开发库之ASIHTTPReq…
- ios开发--app 同时支持iphon…
- iOS 开发资源汇总《转》
- iOS 音频开发之CoreAudio
- iOS label
- UIScrollView 滚动视图—IOS开发
- SQLibs iOS开发常用代码库
- [ios开发异常]whose view&n…
- iOS 给label加下划线或者中划线
- iOS 关于音频开发