2016-06-07 131 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)顺时针' –