iOS关于定制某个控件四个角是否为圆角

时间:2023-03-09 03:43:37
iOS关于定制某个控件四个角是否为圆角

UIView *myView=[[UIView alloc]initWithFrame:CGRectMake(50, 70, 200, 200)];

UIBezierPath * bezierPath = [UIBezierPath bezierPathWithRoundedRect:myView.bounds byRoundingCorners:UIRectCornerBottomLeft |UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];

CAShapeLayer *maskLayer = [CAShapeLayer layer];

maskLayer.frame = myView.bounds;

maskLayer.path = bezierPath.CGPath;

myView.layer.mask = maskLayer;

myView.backgroundColor=[UIColor redColor];

[self.view addSubview:myView];