.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. JAVA获得系统配置文件的System Properties

    来个java获得系统配置文件的 public class SystemProperties { public static void main(String[] args) { Properties ...

  2. poj 2385 Apple Catching(dp)

    Description It and ) in his field, each full of apples. Bessie cannot reach the apples when they are ...

  3. hdu 5245 Joyful(期望的计算,好题)

    Problem Description Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to pain ...

  4. pyqt 图片(label上显示

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from decimal import * from PyQt4.Q ...

  5. servlet基本概念

    一.servlet是一个供其它java程序调用的java类,比方tomcatserver,它不能独自执行,它的执行由servlet引擎来控制和调度. 二.servlet是单例,多线程 针对多个clie ...

  6. go中string和slice no-copy转换

    在go里面,string和slice的互换是需要进行内存拷贝的,虽然在底层,它们都只是用 pointer + len来表示的一段内存. 通常,我们不会在意string和slice的转换带来的内存拷贝性 ...

  7. HDU4496_D-City(并查集删边/逆向)

    D-City Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Sub ...

  8. Android窗口管理服务WindowManagerService对壁纸窗口(Wallpaper Window)的管理分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8550820 Android系统中,壁纸窗口和输 ...

  9. 阿里云部署Docker(5)----管理和公布您的镜像

    出到这节,我在百度搜索了一下"阿里云部署Docker",突然发现怎么会有人跟我写的一样呢?哦,原来是其它博客系统的爬虫来抓取,然后也不会写转载自什么什么的.所以,我最终明确为什么那 ...

  10. 关于jQuery获取checkbox状态的问题

    这位大神概括的很好 http://www.cnblogs.com/wangkongming/p/4002710.html