转载自 http://mobile.51cto.com/hot-404798.htm,略有改动

UnderLineButton.h代码
@interface UnderLineButton : UIButton

+ (UnderLineButton *) underLineButton;

@end
UnderLineButton.m代码
@implementation UnderLineButton

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
} + (UnderLineButton *) underLineButton {
UnderLineButton * button = [[UnderLineButton alloc] init];
return [button autorelease];
} // An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
CGRect textRect = self.titleLabel.frame; //need to put the line at top of descenders (negative value)
CGFloat descender = self.titleLabel.font.descender+2.0f;
CGContextRef contextRef = UIGraphicsGetCurrentContext(); //set to same color as text
CGContextSetStrokeColorWithColor(contextRef, self.titleLabel.textColor.CGColor); CGContextMoveToPoint(contextRef, textRect.origin.x, textRect.origin.y + textRect.size.height + descender); CGContextAddLineToPoint(contextRef, textRect.origin.x + textRect.size.width, textRect.origin.y + textRect.size.height + descender); CGContextClosePath(contextRef);
CGContextDrawPath(contextRef, kCGPathStroke);
} @end

自定义带下划线文本的UIButton的更多相关文章

  1. iOS开发:自定义带下划线文本的UIButton

    Uiunderlinedbutton.h代码 @interface UIUnderlinedButton : UIButton { } + (UIUnderlinedButton *) underli ...

  2. TabTopUnderLineLayout【自定义顶部选项卡(带下划线)】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 自定义顶部选项卡布局LinearLayout类,实现带下划线样式的效果. 备注:如果配合Fragment的话,MainActivit ...

  3. TabTopAutoLayout【自定义顶部选项卡区域(带下划线)(动态选项卡数据且可滑动)】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 自定义顶部选项卡布局LinearLayout类,实现带下划线且可滑动效果.[实际情况中建议使用RecyclerView] 备注:如果 ...

  4. FragmentTabHostUnderLineDemo【FragmentTabHost带下划线】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 使用FragmentTabHost实现顶部选项卡(带下划线效果)展现. 效果图 代码分析 1.该Demo中采用的是FragmentT ...

  5. delphi 仅带下划线的TEdit控件

    在做录入框的时候,很希望有一个只带下划线的文本框,网上介绍的很多,有自己做组件的,须不知Delphi下只需要简单设置几个属性即可达到目的.

  6. 关于python中带下划线的变量和函数 的意义

    总结: 变量: 1.  前带_的变量:  标明是一个私有变量, 只用于标明, 外部类还是可以访问到这个变量 2.  前带两个_ ,后带两个_ 的变量:  标明是内置变量, 3.  大写加下划线的变量: ...

  7. geotools导入shp文件到Oracle数据库时表名带下划线的问题解决

    问题: 最近在做利用geotools导入shp文件到Oracle表中,发现一个问题Oracle表名带下划线时导入失败,问题代码行: dsOracle.getFeatureWriterAppend(or ...

  8. [转]关于python中带下划线的变量和函数的意义

    Python 的代码风格由 PEP 8 描述.这个文档描述了 Python 编程风格的方方面面.在遵守这个文档的条件下,不同程序员编写的 Python 代码可以保持最大程度的相似风格.这样就易于阅读, ...

  9. Python里的单下划线,双下划线,以及前后都带下划线的意义

    Python里的单下划线,双下划线,以及前后都带下划线的意义: 单下划线如:_name 意思是:不能通过from modules import * 导入,如需导入需要:from modules imp ...

随机推荐

  1. bzoj3105【CQOI2013】新nim游戏

    题意:http://www.lydsy.com/JudgeOnline/problem.php?id=3105 sol  :要想必胜则拿完后异或空间不能包含0,即给对手留下一组线性基 为保证拿走的最小 ...

  2. Python matplotlib 柱状图

    matplotlib是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中.它的文档相当完备,并且 ...

  3. config .net webapi to return json.

    1.add content negotiator using System; using System.Collections.Generic; using System.Linq; using Sy ...

  4. mariadb中执行数据库脚本的方法

    为了项目需求,写如下sql数据库脚本: SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for ...

  5. Python学习杂记_2_格式化字符串的一些操作

    name=input("Please input your name: ") sex=input("Please input your sex: ") prin ...

  6. 牛客网 牛客小白月赛1 E.圆与三角形-公式题

    E.圆与三角形   链接:https://www.nowcoder.com/acm/contest/85/E来源:牛客网     这个题把公式推一下, 发现就是1+sinA*r,sinA最大为1,所以 ...

  7. RAID 1-6

    RAID 0 RAID 0亦称为带区集.它将两个以上的磁盘串联起来,成为一个大容量的磁盘.在存放数据时,分段后分散存储在这些磁盘中,因为读写时都可以并行处理,所以在所有的级别中,RAID 0的速度是最 ...

  8. Unix/Linux提权漏洞快速检测工具unix-privesc-check

    Unix/Linux提权漏洞快速检测工具unix-privesc-check   unix-privesc-check是Kali Linux自带的一款提权漏洞检测工具.它是一个Shell文件,可以检测 ...

  9. Beginning Auto Layout Tutorial in iOS 7: Part 6

    Gallery example 屏幕有四个分开的相同的矩形,每个矩形有一个label和一个image view.创建一个Gallery的项目.在Main.storyboard中,拖拉一个view大小为 ...

  10. node.js中的exports和module.exports

    不同的编程语言都有各自的代码组织和复用的方式,如.net.php中的命名空间,python中的import,ruby中的module等,来避免命名空间污染.一直都没搞清楚node中的exports和m ...