UILabel Text 加下划线
.h文件
#import <Foundation/Foundation.h> @interface CustomLabel : UILabel
{
BOOL _isEnabled;
} @property (nonatomic ) BOOL isEnabled; @end .m文件
#import "CustomLabel.h" @implementation CustomLabel @synthesize isEnabled = _isEnabled; - (void)drawTextInRect:(CGRect)rect{
[super drawTextInRect:rect]; CGSize textSize = [[self text] sizeWithFont:[self font]];
CGFloat strikeWidth = textSize.width;
CGRect lineRect; if ([self textAlignment] == NSTextAlignmentRight) {
lineRect = CGRectMake(rect.size.width - strikeWidth, rect.size.height/, strikeWidth, );
} else if ([self textAlignment] == NSTextAlignmentCenter) {
lineRect = CGRectMake(rect.size.width/ - strikeWidth/, rect.size.height/, strikeWidth, );
} else {
lineRect = CGRectMake(, rect.size.height/, strikeWidth, );
} if (_isEnabled) {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextFillRect(context, lineRect);
}
} // 调用 CustomLabel *_label;
_label = [[CustomLabel alloc]initWithFrame:CGRectMake(, , , )];
_label.text = @"这是一个多么美好的世界啊";
_label.backgroundColor = [UIColor clearColor];
_label.isEnabled = YES;
[_label sizeToFit];
_label.textColor = [UIColor redColor];
[self.view addSubview:_label];
UILabel Text 加下划线的更多相关文章
- iOS 给UILabel文字加下划线
摘自:http://blog.sina.com.cn/s/blog_6cd380c10101b6hn.html //带下划线的“注” NSMutableAttributedString可变的属性字符串 ...
- iOS初学,关于变量加下划线问题
为什么做ios开发,变量前要加下划线才有用? 看到这个哥们的解释后,终于明白了,转帖到此. 链接在此:http://www.cocoachina.com/bbs/read.php?tid=234290 ...
- Markdown - 如何给文本加下划线
解决方法 Markdown可以和HTML的语法兼容,可以通过HTML的标签来实现效果: 写法 效果 <u>下划线</u> 下划线 这里解释下,u指的是underline下划线. ...
- css给文字加下划线
语法:linear-gradient(direction, color-stop 1, color-stop 2,……) 简单用法:background-image: linear-gradient( ...
- android假设给TextView或EditText的email链接加下划线,并在点击在email连接上能够弹框显示
怎样把textview的一些文字加上背景色: Spannable str = new SpannableString("#fdsfdfsdfdsfd#"); Matcher mat ...
- android里TextView加下划线的几种方式
如果是在资源文件里: <resources> <string name="hello"><u>phone:0123456</u>&l ...
- ios下划线变量:为什么变量前要加下划线才有用?
先看一段代码. 复制代码 appdelegate.h @property (weak) IBOutlet NSMatrix *StockType; @property (weak) IBOutle ...
- Android TextView加下划线的几种方式
如果是在资源文件里: <resources> <</u></string> <string name="app_name">M ...
- UILabel 字体下方加下划线
UILabel *knowKankan = [[UILabel alloc] initWithFrame:CGRectMake(0, MAINHEIGHT - 78 , MAINWIDTH, ...
随机推荐
- Linux usb子系统(三):通过usbfs操作设备的用户空间驱动
内核中提供了USB设备文件系统(usbdevfs,Linux 2.6改为usbfs,即USB文件系统),它和/proc类似,都是动态产生的.通过在/etc/fstab文件中添加如下一行:none /p ...
- qt简单界面更新代码(菜鸟级)(部分代码)
qt简单界面更新代码(菜鸟级)(部分代码)self.timers_1=QtCore.QTimer(self)self.timers_1.timeout.connect(self.min_1)self. ...
- ASIFormDataRequest 上传图片
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...
- PHP连接Mysql服务器的操作
我们的数据存储在数据库中以后,要把数据和网页联系起来的话,要通过web服务器的解释器进行读取数据,再传递给客户端网页.如图: 这里,我选择了PHP作为学习的解释器.下面就具体来总结一下PHP连接MYS ...
- Eclipse代理设置
这段时间公司实行代理上网,不仅通过浏览器上网须要不停的输入username和password,在本地调试程序时候Eclipse居然也弹出框让输入username和password. 如图: 解决的方法 ...
- 给SharePoint页面加入自己定义页脚Custom footer
给SharePoint页面加入自己定义页脚Custom footer 在公司做站点设计项目时,须要在页面上加入页脚. 非常多人都把页脚忽视了,认为没什么多大用处,事实上 ...
- NSSCanner 提取 指定 字符串
/** * 从msg中提取指定的内容 * * @param msg 字符串集合 * * @return 从msg中提取指定的内容 */ -(NSString*)extractBodyFromMe ...
- [Git] --no-verify
Somtimes, the project might set the commit message guide line, if your commit doesn't meet the requi ...
- Timer.4 - Using a member function as a handler
In this tutorial we will see how to use a class member function as a callback handler. The program s ...
- Linux 下提高make的编译效率
Linux下安装程序,一般都通过包管理器安装,但是包管理器或软件商店里的软件往往不是最新版本的,安装最新版软件时通常是下载源代码进行编译. 编译安装源代码时就离不开make了,但是make是单线程的, ...