首页 > 代码库 > iOS开发:自定义带下划线文本的UIButton
iOS开发:自定义带下划线文本的UIButton
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;
- // need to put the line at top of descenders (negative value)
- CGFloat descender = self.titleLabel.font.descender;
- CGContextRef contextRef = UIGraphicsGetCurrentContext();
- // set to same colour 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
iOS开发:自定义带下划线文本的UIButton
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。