只流傳著如何設(shè)置半角。但是沒有設(shè)置描邊。方法如下:
貝塞爾曲線
//TODO:uiview單邊圓角或者單邊框
CGRect layerFrame=self.addBtn.bounds;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:layerFrame byRoundingCorners:(UIRectCornerTopRight | UIRectCornerBottomRight) cornerRadii:CGSizeMake(5,5)];//圓角大小
//設(shè)置遮罩
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = layerFrame;
maskLayer.path= maskPath.CGPath;
//設(shè)置邊框
CAShapeLayer *borderLayer = [[CAShapeLayer alloc] init];
borderLayer.frame = layerFrame;
borderLayer.path= maskPath.CGPath;
borderLayer.fillColor = [UIColor clearColor].CGColor;
borderLayer.lineWidth=2;
borderLayer.strokeColor = [UIColor blueColor].CGColor;
borderLayer.strokeStart = 0.f;
borderLayer.strokeEnd = 1.f;
self.addBtn.layer.mask = maskLayer;
[self.addBtn.layer addSublayer:borderLayer];
self.addBtn.backgroundColor=[UIColor redColor];