#import "EXButton.h" @implementation EXButton -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self.titleLabel setTextAlignment:NSTextAlignmentCenter]; } return self; } -(void)drawRect:(CGRect)rect { //画贝塞尔曲线之类的 CGFloat lw = 2.0; UIColor *color = KlineColor; [color set];//设置线条颜色 CGFloat d = self.frame.size.width * .8; CGFloat x = (self.width - d)/2.0; UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(x, x, d, d)]; path.lineWidth = lw; [path stroke];//空心的图形 } -(CGRect)imageRectForContentRect:(CGRect)contentRect { CGFloat d = self.width * .8; CGFloat x = (self.width - d)/2.0; return CGRectMake(x, x, d, d); } -(CGRect)titleRectForContentRect:(CGRect)contentRect { return self.bounds; } @end /** 往btn里面加图片如何。 */