设置控件圆角,只设置上面两个角的圆角,下面两个角依然是直角,如图效果:
代码(通过贝塞尔曲线重绘layer层):
UIImageView *picImageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
picImageView.backgroundColor = [UIColor greenColor];
[self.view addSubview:picImageView];
// UIRectCornerBottomRight通过这个设置
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:picImageView.bounds
byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight
cornerRadii:CGSizeMake(10, 10)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = picImageView.bounds;
maskLayer.path = maskPath.CGPath;
picImageView.layer.mask = maskLayer;