码迷,mamicode.com
首页 > 其他好文 > 详细

下划线按钮

时间:2014-07-29 12:43:06      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:des   color   os   io   for   line   size   ui   

#import <UIKit/UIKit.h>

 

@interface CXUnderLineButton : UIButton

 

+ (CXUnderLineButton *) underlinedButton;

 

@end

 

 

#import "CXUnderLineButton.h"

 

@implementation CXUnderLineButton

 

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        // Initialization code

    }

    return self;

}

 

 

+ (CXUnderLineButton*) underlinedButton {

    CXUnderLineButton* button = [[CXUnderLineButton alloc] init];

    return button;

}

 

- (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

    CGFloat offset = 1.f;

    CGContextSetStrokeColorWithColor(contextRef, self.highlighted?[UIColor grayColor].CGColor: self.titleLabel.textColor.CGColor);

    

    CGContextMoveToPoint(contextRef, textRect.origin.x, textRect.origin.y + textRect.size.height + descender + offset);

    

    CGContextAddLineToPoint(contextRef, textRect.origin.x + textRect.size.width, textRect.origin.y + textRect.size.height + descender + offset);

    

    CGContextClosePath(contextRef);

    

    CGContextDrawPath(contextRef, kCGPathStroke); 

 

/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect

{

    // Drawing code

}

*/

 

@end

 

下划线按钮,布布扣,bubuko.com

下划线按钮

标签:des   color   os   io   for   line   size   ui   

原文地址:http://www.cnblogs.com/ldc529/p/3874887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!