IOS UIlabel 、UIButton添加下划线
1.给UILabel 添加下划线
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
label.backgroundColor = [UIColor redColor];
label.numberOfLines = ;
NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"您的待办业务条fasdfasdfosadfjasdkljfklasjklfjasdlkjfklasdjklfjalskdjflkadsj"]];
NSRange contentRange = {,[content length]};
[content addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:contentRange];
label.attributedText = content;
[self.view addSubview:label];
2. http://blog.csdn.net/chaoyuan899/article/details/38306141
方法一:
- NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"查看所有中奖记录"];
- NSRange strRange = {0,[str length]};
- [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange];
- [_awardDisplayBtn setAttributedTitle:str forState:UIControlStateNormal];
方法二:
HyperlinksButton.h
- #import <UIKit/UIKit.h>
- @interface HyperlinksButton : UIButton
- {
- UIColor *lineColor;
- }
- -(void)setColor:(UIColor*)color;
- @end
HyperlinksButton.m
- #import "HyperlinksButton.h"
- @implementation HyperlinksButton
- - (id)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- }
- return self;
- }
- -(void)setColor:(UIColor *)color{
- lineColor = [color copy];
- [self setNeedsDisplay];
- }
- - (void) drawRect:(CGRect)rect {
- CGRect textRect = self.titleLabel.frame;
- CGContextRef contextRef = UIGraphicsGetCurrentContext();
- CGFloat descender = self.titleLabel.font.descender;
- if([lineColor isKindOfClass:[UIColor class]]){
- CGContextSetStrokeColorWithColor(contextRef, lineColor.CGColor);
- }
- CGContextMoveToPoint(contextRef, textRect.origin.x, textRect.origin.y + textRect.size.height + descender+1);
- CGContextAddLineToPoint(contextRef, textRect.origin.x + textRect.size.width, textRect.origin.y + textRect.size.height + descender+1);
- CGContextClosePath(contextRef);
- CGContextDrawPath(contextRef, kCGPathStroke);
- }
- @end
直接将这个类 copy 到工程中,,然后将需要加下划线的 Button 类名改为 HyperlinksButton就可以了,提供了 setColor: 这个接口,可以设置下划线颜色,代码很简单,不解释了。UILabel 同理可得。
示例结果:
代码在这里。
IOS UIlabel 、UIButton添加下划线的更多相关文章
- iOS开发-UILabel和UIButton添加下划线
关于UILabel和UIButton有的时候需要添加下划线,一般有两种方式通过默认的NSMutableAttributedString设置,第二种就是在drawRect中画一条下划线,本文就简单的选择 ...
- UILabel和UIButton添加下划线
关于UILabel和UIButton有的时候需要添加下划线,一般有两种方式通过默认的 NSMutableAttributedString设置,第二种就是在drawRect中画一条下划线,本文就简单的选 ...
- iOS 给UILabel文字加下划线
摘自:http://blog.sina.com.cn/s/blog_6cd380c10101b6hn.html //带下划线的“注” NSMutableAttributedString可变的属性字符串 ...
- vim显示行号、语法高亮、自动缩进、添加下划线的设置
ubuntu默认是没有安装vim的,所以设置以前请先安装vim:sudo apt-get install vim. 然后 打开vim的配置文件:sudo vim /etc/vim/vimrc 或者 s ...
- Android 给EditText添加下划线
在安卓高版本,默认是有下划线的,其默认下划线的颜色是由其主题颜色来控制的! 控制如下: <style name="AppTheme" parent="Theme.A ...
- "为文本添加下划线"组件:<u> —— 快应用组件库H-UI
 <import name="u" src="../Common/ui/h-ui/text/c_tag_underline"></impor ...
- UILabel,文字添加下划线,中划线
//显示下划线 //中划线 // NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber nu ...
- TextView 为部分文字添加下划线,并实现单击事件
在开发应用的过程中经常会遇到显示一些不同的字体风格的信息,如关键词高亮显示的等.对于类似的情况,一般我们会想着使用多个TextView去实现,对于每个TextView设置不同的字体风格来满足需求. ...
- 【界面优化】使用viewpagerindicator添加下划线滑动动画
开源代码viewpagerindicator里面没有实现tab下划线切换过程中的移动动画,都是很突兀的多个fragement之间的切换,导致用户体验略差,google了下相关问题,发现一片博文: ht ...
随机推荐
- 【GLSL教程】(五)卡通着色 【转】
http://blog.csdn.net/racehorse/article/details/6641623 引言 卡通着色可能是最简单的非真实模式shader.它使用很少的颜色,通常是几种色调(to ...
- Web.config配置文件详解(新手必看) 【转】
来源 :http://www.cnblogs.com/gaoweipeng/archive/2009/05/17/1458762.html 花了点时间整理了一下ASP.NET Web.config配置 ...
- 2017.2.28 activiti实战--第五章--用户与组及部署管理(三)部署流程及资源读取
学习资料:<Activiti实战> 第五章 用户与组及部署管理(三)部署流程及资源读取 内容概览:如何利用API读取已经部署的资源,比如读取流程定义的XML文件,或流程对应的图片文件. 以 ...
- DevExpress控件之TreeList
基于v18.1 使用AppendNode方法手动赋值时,首先要添加treeListColumn 默认样式 修改后的样式 1 ...
- UNP学习笔记(第五章 TCP客户/服务程序实例)
我们将在本章使用前一章中介绍的基本函数编写一个完整的TCP客户/服务器程序实例 这个简单得例子是执行如下步骤的一个回射服务器: TCP回射服务器程序 #include "unp.h" ...
- Android UI开发神兵利器之Icon
好的设计离不开Icon 话不多.介绍2个国外的站点,一个用来找Icon,一个用来搞页面设计 http://dryicons.com/free-icons/ http://www.webdesignsh ...
- MySQL系列:innodb源代码分析之线程并发同步机制
innodb是一个多线程并发的存储引擎,内部的读写都是用多线程来实现的,所以innodb内部实现了一个比較高效的并发同步机制. innodb并没有直接使用系统提供的锁(latch)同步结构,而是对其进 ...
- 一份还热乎的蚂蚁面经(已拿Offer)!附答案!!
本文来自我的知识星球的球友投稿,他在最近的校招中拿到了蚂蚁金服的实习生Offer,整体思路和面试题目由作者--泽林提供,部分答案由Hollis整理自知识星球<Hollis和他的朋友们>中「 ...
- requestWindowFeature使用详解
requestWindowFeature可以设置的值有: // 1.DEFAULT_FEATURES:系统默认状态,一般不需要指定 // 2.FEATURE_CONTEXT_MENU:启 ...
- 移除WordPress文章图片的宽度和高度属性
通过WordPress自身的媒体上传功能插入到文章的图片,都会默认添加了高度和宽度属性: <img title="使用 Chrome Workspace 进行网站调试 | 倡萌的自留地 ...