使用 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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容