.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. hdu 5433 Xiao Ming climbing(bfs+三维标记)

    Problem Description   Due to the curse made by the devil,Xiao Ming is stranded on a mountain and can ...

  2. 创建UIButton

    UIButtonCreate.h #import <UIKit/UIKit.h> @interface UIButtonCreate : UIButton /** * 创建UIButton ...

  3. 使用Open Flash Chart(OFC)制作图表(Struts2处理)

    Java开源项目中制作图表比较出色的就是JFreeChart了,相信大家都听说过,它不仅可以做出非常漂亮的柱状图,饼状图,折线图基本图形之外,还能制作甘特图,仪表盘等图表.在Web应用中可以为项目增色 ...

  4. python学习之路-3 初始python数据类型以及文件操作

    本篇涉及内容 set集合 函数 三元运算 文件操作 set集合 set是一个无序的且不重复的元素集合 1.创建set集合的方法 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...

  5. struts2——配置struts.xml文件

    在struts2框架中struts.xml是应当放到src的根目录,程序编译后会将struts.xml放到WEB-INF/classes目录下. Struts2在web.xml中的一般配置如下: &l ...

  6. sql注入数据库修复方法

    1.第一种情况是 需要将指定的 注入字符串全部替换掉(仅替换注入的字符串为空) declare @delStr nvarchar(500) set @delStr='<script src=ht ...

  7. [Python][MachineLeaning]Python Scikit-learn学习笔记1-Datasets&Estimators

    Scikit-learn官网:http://scikit-learn.org/stable/index.html Datasets 标准的数据集格式为一组多维特征向量组成的集合.数据集的标准形状(sh ...

  8. AFNetWorking 关于manager.requestSerializer.timeoutInterval 不起作用的问题

    之前一直遇到关于AFNetWorking请求时间设置了但是不起作用的情况,现用如下方式设置AF的超市时间即可. [manager.requestSerializer willChangeValueFo ...

  9. OpenCV——Rect矩阵类

    成员变量x.y.width.height,分别为左上角点的坐标和矩形的宽和高. 常用的成员函数有: Size()返回值为一个Size area()返回矩形的面积 contains(Point)用来判断 ...

  10. JS 混淆加密

    http://www.javascriptobfuscator.com/Javascript-Obfuscator.aspx http://www.javascriptobfuscator.com/d ...