Uiunderlinedbutton.h代码
- @interface UIUnderlinedButton : UIButton {
- }
- + (UIUnderlinedButton *) underlinedButton;
- @end
Uiunderlinedbutton.m代码
- @implementation UIUnderlinedButton
-
- + (UIUnderlinedButton*) underlinedButton {
- UIUnderlinedButton* button = [[UIUnderlinedButton alloc] init];
- return [button autorelease];
- }
-
- - (void) drawRect:(CGRect)rect {
- CGRect textRect = self.titleLabel.frame;
-
- CGFloat descender = self.titleLabel.font.descender;
-
- CGContextRef contextRef = UIGraphicsGetCurrentContext();
-
- 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
iOS开发:自定义带下划线文本的UIButton
原文:http://www.cnblogs.com/lgphp/p/4109635.html