UIView *view = [[UIView alloc]initWithFrame:CGRectMake(50, 100, 100, 100)]; view.backgroundColor = [UIColor lightGrayColor]; // 这里指出要设置哪些角为圆角 UIRectCorner corner = (UIRectCornerTopLeft|UIRectCornerBottomLeft); UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(10, 10)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.path = path.CGPath; // 使用maskView来完成 view.layer.mask = maskLayer; [self.view addSubview:view];
效果如下图: