只流传着如何设置半角。但是没有设置描边。方法如下:
贝塞尔曲线
//TODO:uiview单边圆角或者单边框
CGRect layerFrame=self.addBtn.bounds;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:layerFrame byRoundingCorners:(UIRectCornerTopRight | UIRectCornerBottomRight) cornerRadii:CGSizeMake(5,5)];//圆角大小
//设置遮罩
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = layerFrame;
maskLayer.path= maskPath.CGPath;
//设置边框
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];