使用CAShapeLayer和UIBezierPath绘制色盘

来源:互联网 发布:数据库游标是什么 编辑:程序博客网 时间:2024/06/13 01:15

-(void)drawArcWithStartAngel:(CGFloat)startAngle andEndAngle:(CGFloat)endAngle andColor:(UIColor *)fillColor{

    UIBezierPath *path=[UIBezierPath bezierPath];

    [path moveToPoint:self.view.center];

    [path addLineToPoint:CGPointMake(cos(startAngle)*100+self.view.center.x, sin(startAngle)*100+self.view.center.y)];

    [path addArcWithCenter:self.view.center radius:100 startAngle:startAngle endAngle:endAngle clockwise:YES];

    [path moveToPoint:CGPointMake(cos(endAngle)*100+self.view.center.x, sin(endAngle)*100+self.view.center.y)];

    [path addLineToPoint:self.view.center];

    [path closePath];


    CAShapeLayer *shapeLayer=[CAShapeLayer layer];

    shapeLayer.frame=self.view.frame;

    shapeLayer.path=path.CGPath;   

    shapeLayer.strokeColor=[UIColor whiteColor].CGColor;

    shapeLayer.fillColor=fillColor.CGColor;

    [self addTap:shapeLayer];

    [self.view.layer addSublayer:shapeLayer];

}

0 0
原创粉丝点击