Specify the rounded corner of iOS development
If you want to set all the four corners of the UIView to rounded corners, the procedure is quite simple. You only need to set the cornerRadius attribute of the Layer (the QuartzCore framework is required for the project ). This method is not useful if you want to specify a few corners (less than 4) as the rounded corner while others remain unchanged.
In this case, Stackoverflow provides several solutions. The simplest and most elegant solution is to use UIBezierPath. The following is a sample code.
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(120, 10, 80, 80)];view2.backgroundColor = [UIColor redColor];[self.view addSubview:view2]; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];maskLayer.frame = view2.bounds;maskLayer.path = maskPath.CGPath;view2.layer.mask = maskLayer;
Where,
byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
Specifies the corner to be rounded. This parameter is of the UIRectCorner type and has the following optional values:
* UIRectCornerTopLeft* UIRectCornerTopRight* UIRectCornerBottomLeft* UIRectCornerBottomRight* UIRectCornerAllCorners
It is easy to see the meaning of the representative from the name, just use "|" to combine.