带下划线的按钮
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
@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
相关文章推荐
- Color the ball
- DSP生成hex文件、生成bin文件方法
- 网络吞吐量
- (转载)使用Links方法安装Eclipse插件
- Visual Studio中 ATL CLR MFC Win32 区别
- 容易被忽视的Linux磁盘配额设置
- 常用的mysql命令
- collectionview头部悬浮
- 思路超简单的Android Socket 通信 Demo 注释详细
- 创建android项目时没有自动生成R.java文件的解决方法
- VS编程中_T与L的区别
- android 通过Camera和Surfaceview实现照相 图片预览 保存图片到本地 手动聚焦 FaceDetectionListener实现人脸识别
- CentOS linux 高可用集群之heartbeat
- nyoj--747--蚂蚁的难题(三)(dp背包)
- Linux下mysql安装和一些基础操作
- [LeetCode]Longest Substring Without Repeating Characters
- 验证码识别
- SDN学习笔记
- 黑马视频-触发器
- 自定义exception