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];
效果以下圖:blog