iOS 控件设置单个或多个圆角


+(void)viewBeizerRect:(CGRect)rect view:(UIView *)view corner:(UIRectCorner)corner cornerRadii:(CGSize)radii{
UIBezierPath *maskPath= [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radii];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame =view.bounds;
maskLayer.path = maskPath.CGPath;
view.layer.mask = maskLayer;

}


示例


UIView *view=[[UIView alloc]initWithFrame:CGRectMake(100, 270, 100, 100)];
view.backgroundColor=[UIColor greenColor];
[self.view addSubview:view];
[self viewBeizerRect:view.bounds view:view corner:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(25, 25)];

你可能感兴趣的:(iOS 控件设置单个或多个圆角)