CGFloat containerViewW = 200;
CGFloat containerViewH = 200;
CGFloat containerViewX = (self.view.bounds.size.width - containerViewW) / 2;
CGFloat containerViewY = (self.view.bounds.size.height - containerViewH) / 2;
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(containerViewX, containerViewY, containerViewW, containerViewH)];
containerView.backgroundColor = [UIColor blueColor];
[self.view addSubview:containerView];
/* 指定哪个角为圆角:
UIRectCornerTopLeft:左上
UIRectCornerTopRight:右上
UIRectCornerBottomLeft:左下
UIRectCornerBottomRight:右下
*/
UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:containerView.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(20, 20)];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = path.CGPath;
containerView.layer.mask = shapeLayer;
网友评论