美文网首页
使用 UIBezierPath 画一个顶端有圆角的 Butto

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

作者: Young_Blood | 来源:发表于2016-04-13 10:05 被阅读255次
//  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 画一个顶端有圆角的 Butto

      本文链接:https://www.haomeiwen.com/subject/scbwlttx.html