2016-06-07 171 views
0

我正在使用下面的代碼來顯示像三角形視圖的指針,如下圖所示。帶圓角的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]; 

這工作正常,但我希望三角形視圖的指向邊緣四捨五入。如何使它圓潤?任何幫助表示讚賞!

enter image description here

+0

這不行! – Nikhil

+0

將lineCapStyle設置爲kCGLineCapRound(在貝塞爾路徑上)以圓形邊緣繪製線條的末端。 – arturdev

+0

triangleView.layer.cornerRadius = 15.0f; 這使得這個三角形的左側角的角半徑曲線。除此之外沒有什麼工作linecapstyle也不工作。 – Nikhil

回答

0

更改lineJoinkCALineJoinRound

triangleMaskLayer.lineJoin = kCALineJoinRound;

+0

我試過這個,但似乎沒有工作! – Nikhil

+0

「@」Armands你有什麼想法,爲什麼linejoin和kCGLineCapRound不工作在我的情況? – Nikhil

+0

您可以隨時使用' - (void)addArcWithCenter :(CGPoint)中心半徑:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle順時針:(BOOL)順時針' –