ios-给view添加部分圆角

简单粗暴点  直接上代码吧

-(void)createUI{
   
    UIView * view1 = [[UIView alloc]initWithFrame:CGRectMake(50, 120, 100, 100)];
    view1.backgroundColor = [UIColor grayColor];
    [self.view addSubview:view1];
   
    CGFloat radius = 15; // 圆角大小
    UIRectCorner corner = UIRectCornerTopLeft | UIRectCornerBottomLeft; // 圆角位置
    UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:view1.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = view1.bounds;
    maskLayer.path = path.CGPath;
    view1.layer.mask = maskLayer;
   
}

你可能感兴趣的:(ios-给view添加部分圆角)