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, ...
随机推荐
- textChanged(*)重点
# -*- coding: cp936 -*- import sys from PyQt4 import QtCore, QtGui class MyDialog(QtGui.QDialog): de ...
- UITableView使用总结和性能优化
UITableView使用总结和性能优化 UITableView有两种风格:UITableViewStylePlain和UITableViewStyleGrouped.如 果我们查看UITabl ...
- c++之 变量
变量的基本操作 变量就是一个可以变化的量,变量由变量类型.变量名.初始值(可选)组成,例如: int abc = 10; 变量类型:int 变量名:abc 初始值:10 // 该值为可选项,在创建变量 ...
- Ubuntu14.04配置cuda-convnet
转载请注明:http://blog.csdn.net/stdcoutzyx/article/details/39722999 在上一个链接中,我配置了cuda,有强大的GPU,自然不能暴殄天物,让资源 ...
- 跟我学系列教程——《13天让你学会Redis》火热报名中
学习目标 每天2小时,13天让你学会Redis. 本课程针对Redis新手,甚至连Redis是什么都没有听说过的同学.课程会具体介绍Redis是什么以及为什么要使用Redis,结合项目实践旨在让学生从 ...
- POJ 1469 ZOJ1140 二分匹配裸题
很裸,左点阵n,右点阵m 问最大匹配是否为n #include <cstdio> #include <cstring> #include <vector> usin ...
- [Hapi.js] Extending the request with lifecycle events
Instead of using middlware, hapi provides a number of points during the lifecycle of a request that ...
- WEB服务器4--IIS中网站、Web应用程序和虚拟目录
网站.Web应用程序和虚拟目录 在IIS中可以创建网站.Web 应用程序和虚拟目录,以便与计算机网络上的用户共享信息. “网站”.“Web 应用程序”和“虚拟目录”这三个概念的关系如图 8‑1所示. ...
- jQuery 事件 - error() 方法
实例 如果图像不存在,则用一段预定义的文本取代它: $("img").error(function(){ $("img").replaceWith(" ...
- python的编码问题研究------使用scrapy体验
python转码译码 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !impo ...