- (void)loadView {
[super loadView];
CGFloat width = 200;
CGFloat height = 400;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 150, width, height)];
view.backgroundColor = [UIColor redColor];
[self.view addSubview:view];
CGFloat radius = 10; // 半径
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 0)];
[path addLineToPoint:CGPointMake(width, 0)];
[path addLineToPoint:CGPointMake(width, height / 2 - radius)];
[path addArcWithCenter:CGPointMake(width, height / 2) radius:radius startAngle:1.5 * M_PI endAngle:0.5 * M_PI clockwise:NO]; // 右面凹巢
[path addLineToPoint:CGPointMake(width, height)];
[path addLineToPoint:CGPointMake(0, height)];
[path addLineToPoint:CGPointMake(0, height / 2 + radius)];
[path addArcWithCenter:CGPointMake(0, height / 2) radius:radius startAngle:0.5 * M_PI endAngle:1.5 * M_PI clockwise:NO]; // 左面凹巢
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = view.bounds;
maskLayer.path = path.CGPath;
view.layer.mask = maskLayer;
/**
圆上方:1.5π
圆右方:2π
圆下方:0.5π
圆左方:π
*/
}
image
网友评论