使用 UIBezierPath 画一个顶端有圆角的 Button

//  Created by LiuDunhui on 16/4/13.
//  Copyright © 2016年 LDH. All rights reserved.
//

#import "WLWTopLeftAndRightCornerButton.h"

@implementation WLWTopLeftAndRightCornerButton

/**
 *  画一个顶端有圆角的Button
 *
 *  @param rect  范围
 */
- (void)drawRect:(CGRect)rect{
    
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(20, 20)];
    
    UIColor *fillColor = [UIColor whiteColor];
    [fillColor set];
    
    // 进行裁剪
    CAShapeLayer *shape = [[CAShapeLayer alloc] init];
    [shape setPath:path.CGPath];
    self.layer.mask = shape;
    
    
    [path fill];
}

@end

你可能感兴趣的:(使用 UIBezierPath 画一个顶端有圆角的 Button)