#import <UIKit/UIKit.h>
@interface NDPageSelectBtn : UIButton
@property(nonatomic, strong) UIColor *indicatorColor;
@end
#import "NDPageSelectBtn.h"
@implementation NDPageSelectBtn
@synthesize indicatorColor=_indicatorColor;
+ (id)buttonWithType:(UIButtonType)buttonType
{
NDPageSelectBtn *btn = [super buttonWithType:buttonType];
[btn setTitleColor:kMainBlackColor forState:UIControlStateNormal];
return btn;
}
- (void)setIndicatorColor:(UIColor *)color
{
_indicatorColor = color;
[self setTitleColor:color forState:UIControlStateSelected];
self.titleLabel.font = [UIFont systemFontOfSize:16.0f];
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
if (self.selected) {
UIBezierPath *bezierPath = [UIBezierPath bezierPath];
CGRect lableFram = self.titleLabel.frame;
[bezierPath moveToPoint:CGPointMake(lableFram.origin.x, CGRectGetHeight(rect)-2)];
[bezierPath addLineToPoint:CGPointMake(CGRectGetMaxX(lableFram), CGRectGetHeight(rect)-2)];
[bezierPath setLineWidth:1.5f];
[self.indicatorColor setStroke];
[bezierPath stroke];
}
}
@end