.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 加下划线的更多相关文章

  1. iOS 给UILabel文字加下划线

    摘自:http://blog.sina.com.cn/s/blog_6cd380c10101b6hn.html //带下划线的“注” NSMutableAttributedString可变的属性字符串 ...

  2. iOS初学,关于变量加下划线问题

    为什么做ios开发,变量前要加下划线才有用? 看到这个哥们的解释后,终于明白了,转帖到此. 链接在此:http://www.cocoachina.com/bbs/read.php?tid=234290 ...

  3. Markdown - 如何给文本加下划线

    解决方法 Markdown可以和HTML的语法兼容,可以通过HTML的标签来实现效果: 写法 效果 <u>下划线</u> 下划线 这里解释下,u指的是underline下划线. ...

  4. css给文字加下划线

    语法:linear-gradient(direction, color-stop 1, color-stop 2,……) 简单用法:background-image: linear-gradient( ...

  5. android假设给TextView或EditText的email链接加下划线,并在点击在email连接上能够弹框显示

    怎样把textview的一些文字加上背景色: Spannable str = new SpannableString("#fdsfdfsdfdsfd#"); Matcher mat ...

  6. android里TextView加下划线的几种方式

    如果是在资源文件里: <resources> <string name="hello"><u>phone:0123456</u>&l ...

  7. ios下划线变量:为什么变量前要加下划线才有用?

    先看一段代码.   复制代码 appdelegate.h @property (weak) IBOutlet NSMatrix *StockType; @property (weak) IBOutle ...

  8. Android TextView加下划线的几种方式

    如果是在资源文件里: <resources> <</u></string> <string name="app_name">M ...

  9. UILabel 字体下方加下划线

        UILabel *knowKankan = [[UILabel alloc] initWithFrame:CGRectMake(0, MAINHEIGHT - 78 , MAINWIDTH, ...

随机推荐

  1. QT 4.7支持中文(QT4.7)(中文)(makeqpf)

    QT 4.7支持中文(QT4.7)(中文)(makeqpf) 摘要: QT4.7.0在移植到开发板上的时候,中文支持是必不可少的,如何让QT支持中文,如何制作QT支持的字体文件,如何使QT UI编辑器 ...

  2. ubuntu下php安装xdebug

    1.安装  sudo apt-get install php5-xdebug 2.配置  修改 php .ini 路径: /etc/php5/apache2/php.ini (这里可能有不同,不同的u ...

  3. eclipse配置maven + 创建maven项目

        登录|注册     努力+坚持,而且还很年轻   目录(?)[+] 在现实的企业中,以低成本.高效率.高质量的完成项目,不仅仅需要技术大牛,企业更加需要管理大牛,管理者只懂技术是远远不够的.当 ...

  4. Bin & Jing in wonderland(概率,组合数学)

    Problem 2103 Bin & Jing in wonderland Accept: 201    Submit: 1048 Time Limit: 1000 mSec    Memor ...

  5. Leetcode 238 Product of Array Except Self 时间O(n)和空间O(1)解法

    1. 问题描写叙述 给定一个n个整数的数组(n>1n>1)nums,返回一个数组output,当中的元素outputioutput_i的值为原数组nums中除numsinums_i之外的全 ...

  6. TNS-00512: Address already in use-TNS-12542: TNS:address already in use

    监听启动或是停止时提示如下错误:TNS-12542: TNS:address already in use TNS-12560: TNS:protocol adapter error TNS-0051 ...

  7. E514:write error(file system full?)

    vi编辑某文件,保存时报错,提示:E514: write error (file system full?)---写入错误,磁盘满了? 查看磁盘空间:df -h根目录磁盘空间已满,used%100. ...

  8. [core java学习笔记][第十章部署应用程序]

    第10章 部署应用程序和applet jar文件 Java Web Start 10.1 jar文件 jar文件就是一个压缩了类,图像和声音的ZIP压缩文件 创建一个新的JAR文件应该使用的常见命令格 ...

  9. Linq:切勿使用 Count() > 0 来判断集合非空

    原文(http://www.cnblogs.com/ldp615/archive/2011/12/11/2284154.html) Linq 出现之前,我们通常使用下面的方式来判断集合是否非空,即集合 ...

  10. Redis 安装教程 (Windows 2.6.13 稳定版)

    redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted set ...