带下划线的按钮

#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



阅读更多
个人分类: IOS-项目汇总
上一篇collectionview头部悬浮
下一篇自定义textFeild
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭