我正在使用下面的代碼來顯示像三角形視圖的指針,如下圖所示。帶圓角的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];
這工作正常,但我希望三角形視圖的指向邊緣四捨五入。如何使它圓潤?任何幫助表示讚賞!
這不行! – Nikhil
將lineCapStyle設置爲kCGLineCapRound(在貝塞爾路徑上)以圓形邊緣繪製線條的末端。 – arturdev
triangleView.layer.cornerRadius = 15.0f; 這使得這個三角形的左側角的角半徑曲線。除此之外沒有什麼工作linecapstyle也不工作。 – Nikhil