設(shè)置控件圓角,只設(shè)置上面兩個角的圓角,下面兩個角依然是直角,如圖效果:
代碼(通過貝塞爾曲線重繪layer層):
UIImageView *picImageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
picImageView.backgroundColor = [UIColor greenColor];
[self.view addSubview:picImageView];
// UIRectCornerBottomRight通過這個設(shè)置
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;