关闭

带下划线的按钮

135人阅读 评论(0) 收藏 举报
分类:

#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



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:28078次
    • 积分:950
    • 等级:
    • 排名:千里之外
    • 原创:62篇
    • 转载:53篇
    • 译文:0篇
    • 评论:0条