UILabel和UIButton添加下划线
来源:互联网 发布:淘宝beta版已过期 编辑:程序博客网 时间:2024/05/16 18:41
原文 http://www.cnblogs.com/xiaofeixiang/p/4582292.html
关于UILabel和UIButton有的时候需要添加下划线,一般有两种方式通过默认的 NSMutableAttributedString设置,第二种就是在drawRect中画一条下划线,本文就简单的选择第一种,第二种有兴趣的可以自己研究一下。
UILabel设置下划线:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 310, 50)]; label.backgroundColor = [UIColor redColor]; [label setLineBreakMode:NSLineBreakByWordWrapping]; label.numberOfLines =3; [label setFont:[UIFont systemFontOfSize:14]]; NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"博文地址:http://www.cnblogs.com/xiaofeixiang 博客园-FlyElephant QQ群:228407086"]]; NSRange contentRange = {0,[content length]}; [content addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];label.attributedText = content;[self.view addSubview:label];</pre><br>
UIButton设置下划线:
UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(10, 200, 80, 30)];
NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:@"FlyElephant"];
NSRange titleRange = {0,[title length]};
[title addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:titleRange];
[button setAttributedTitle:title
forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor redColor]];
[button.titleLabel setFont:[UIFont systemFontOfSize:14]];
[self.view addSubview:button];最终效果如下:
</article>
0 0
- UIButton和UILabel添加下划线
- UILabel和UIButton添加下划线
- 关于UILabel和UIButton添加下划线
- 给 UIButton、UILabel添加下划线
- UIButton和的UILabel添加下划线,中划线
- IOS UIButton UILabel 等title 添加下划线 swift 版
- UILabel 添加中划线和下划线
- UILabel添加下划线
- UILabel 文案添加下划线
- UILabel添加下划线
- 代码(XIB)实现UIButton、UILabel文字添加下划线小技巧
- 给UILabel 或者 UIButton标题加下划线
- 给UILabel 或者 UIButton标题加下划线
- 给UILabel 或者 UIButton标题加下划线
- 给UILabel 或者 UIButton标题加下划线
- 给UILabel 或者 UIButton标题加下划线
- 给UILabel 或者 UIButton标题加下划线
- 给UILabel 或者 UIButton标题加下划线
- Android开发-轮播图设计
- RadioButton调用setChecked()不起作用
- Android 如何引用com.android.internal.R目录下的资源
- java之全文索引搜索lucene之增删改查文档与中文分词搜索
- 系统学习深度学习(十二)--池化
- UILabel和UIButton添加下划线
- Cocos仿unity按钮机制
- Eclipse 显示.setting目录
- OracleStudy--OracleSQL执行计划查看(MindMap)
- STL-set
- DEVEXPRESS GridControl自定义分组组名
- Django-模板
- 汉字数字混合排序
- Log4net配置与使用简要说明