1.绘制按钮背景图形
@interface CustomBezierView : UIView
@property (nonatomic, assign) BOOL isFill;
@property (nonatomic, assign) BOOL isLeft;
@end
@implementation CustomBezierView
- (instancetype)initWithFrame:(CGRect)frame isFill:(BOOL)isFill isLeft:(BOOL)isLeft{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor whiteColor];
self.isFill = isFill;
self.isLeft = isLeft;
}
return self;
}
- (void)drawRect:(CGRect)rect {
//使用Bezier绘制图形: rect设置大小 byRoundingCorners设置圆角位置 cornerRadii圆角大小
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:(self.isLeft?UIRectCornerBottomLeft:UIRectCornerBottomRight) | (self.isLeft?UIRectCornerTopLeft:UIRectCornerTopRight) cornerRadii:CGSizeMake(17, 17)];
maskPath.lineWidth = 1;
[HEXACOLOR(0xA82D2D, 1) set];
self.isFill?[maskPath fill]:[maskPath stroke];
}
@end
2.去除按钮点击时的高亮效果
self.totalStatis.adjustsImageWhenDisabled = NO;
self.totalStatis.adjustsImageWhenHighlighted = NO;
3.视图转image
- (UIImage )imageFromView:(UIView)view{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, view.layer.contentsScale);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}