您的位置:首页 > 其它

带下划线的按钮

2015-11-18 19:27 253 查看
#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: