带圆角的Bezierpath
问题描述:
我正在使用下面的代码来显示像三角形视图的指针,如下图所示。带圆角的Bezierpath
UIView *triangleView = [[UIView alloc] initWithFrame:CGRectMake(70.0f,58.0f, self->_createAccountView.frame.size.width ,20.0f)];
UIBezierPath* trianglePath = [UIBezierPath bezierPath];
[trianglePath moveToPoint:CGPointMake(0, 0)];
[trianglePath addLineToPoint:CGPointMake((self->_createAccountView.frame.size.width/7) -8, (self->_createAccountView.frame.size.height/4))];
[trianglePath addLineToPoint:CGPointMake((self->_createAccountView.frame.size.width/5) , 0)];
[trianglePath closePath];
trianglePath.lineJoinStyle = kCGLineJoinRound;
CAShapeLayer *triangleMaskLayer = [CAShapeLayer layer];
[triangleMaskLayer setPath:trianglePath.CGPath];
triangleView.backgroundColor = [UIColor colorWithRed:1.00 green:1.00 blue:1.00 alpha:1.0];
triangleView.layer.mask = triangleMaskLayer;
[self->_AccountView addSubview:triangleView];
这工作正常,但我希望三角形视图的指向边缘四舍五入。如何使它圆润?任何帮助表示赞赏!
答
更改lineJoin
到kCALineJoinRound
。
triangleMaskLayer.lineJoin = kCALineJoinRound;
这不行! – Nikhil
将lineCapStyle设置为kCGLineCapRound(在贝塞尔路径上)以圆形边缘绘制线条的末端。 – arturdev
triangleView.layer.cornerRadius = 15.0f; 这使得这个三角形的左侧角的角半径曲线。除此之外没有什么工作linecapstyle也不工作。 – Nikhil