iOS UIBezierPath图形绘制

原创 2016年06月01日 14:19:34
#pragma mark - 绘制外圈路径
- (void)drawOuter:(CGRect)rect{
    
    UIColor *color = [UIColor colorWithRed:224/255.0f green:224/255.0f blue:224/255.0f alpha:1.0f];
    [color set]; //设置线条颜色
    
    UIBezierPath    *bPath = [UIBezierPath bezierPathWithArcCenter:_centerPoint
                                                            radius:_outerRadiusWidth-2
                                                        startAngle:M_PI
                                                          endAngle:2*M_PI
                                                         clockwise:YES];
    
    bPath.lineWidth = _outerWidth;
    bPath.lineCapStyle = kCGLineCapRound; //线条拐角
    bPath.lineJoinStyle = kCGLineCapRound; //终点处理
 }

#pragma mark - 绘制内圈进度路径
- (void)setInnerProgess{
    if (_shapeLayer) {
        [_shapeLayer removeFromSuperlayer];
    }
    _shapeLayer = [CAShapeLayer layer];
    _shapeLayer.strokeColor = [[TNColor ff6633Color] CGColor];
    _shapeLayer.fillColor = [[UIColor clearColor] CGColor];
    _shapeLayer.lineWidth = _innerWidth;
    _shapeLayer.lineCap = kCALineCapRound;
    _shapeLayer.lineJoin = kCALineJoinRound;
    _shapeLayer.path = [UIBezierPath bezierPathWithArcCenter:_centerPoint radius:_innerRadiusWidth startAngle:DEGREES_TO_RADIANS(_beginAngle) endAngle:DEGREES_TO_RADIANS(_rotationAngle) clockwise:YES].CGPath;
    [self.layer addSublayer:_shapeLayer];
}
#pragma mark - 绘制指示线
- (void)drawIndicatorLine{
    
    UIColor *color = [TNColor ff6633Color];
    [color set]; //设置线条颜色
    
    
    NSInteger  _total = 5;
    
    CGFloat x0 = _centerPoint.x;
    CGFloat y0 = _centerPoint.y;
    int i = 0;
    for (i = 0; i < _total; i++) {
        UIBezierPath *bezierPath = [UIBezierPath bezierPath];
        bezierPath.lineWidth = 2;
        
        CGFloat x1 = x0 + cosf(_startAngle + _totalAngle*i/(_total-1))*(_lineRadiusWidth-6);
        CGFloat y1 = y0+ sinf(_startAngle + _totalAngle*i/(_total-1))*(_lineRadiusWidth-6);
        
        CGFloat x2 = x0 + cosf(_startAngle + _totalAngle*i/(_total-1))*_lineRadiusWidth;
        CGFloat y2 = y0+ sinf(_startAngle + _totalAngle*i/(_total-1))*_lineRadiusWidth;
        
        [bezierPath moveToPoint:CGPointMake(x1, y1)];
        [bezierPath addLineToPoint:CGPointMake(x2, y2)];
        
        [bezierPath stroke];
    }

}


#pragma mark - 绘制文字
- (void)drawMothsLabel{
    [_mothsLabelArray removeAllObjects];
    
    for (int i = 0; i < _moths.count; i++) {
        NSString *mothInfo = _moths[i];
        
        CGFloat x0 = _centerPoint.x;
        CGFloat y0 = _centerPoint.y;
        CGFloat x = x0 + cosf(_startAngle + _totalAngle*i/(_moths.count-1))*_labelRadiusWidth;
        CGFloat y = y0+ sinf(_startAngle + _totalAngle*i/(_moths.count-1))*_labelRadiusWidth;
        CGRect rect = CGRectMake(x-30, y-20, 60, 25);
        
        CGFloat angleDegrees = 0;
        if (i==0) {
            angleDegrees = -90;
        }else if (i==1){
            angleDegrees = -45;
        }else if (i==2){
            angleDegrees = 0;
        }else if (i==3){
            angleDegrees = 45;
        }else if (i==4){
            angleDegrees = 90;
        }
        
        CATextLayer* textLayer = [[CATextLayer alloc] init];
        textLayer.string = mothInfo;
        textLayer.frame = rect;
        textLayer.alignmentMode = kCAAlignmentCenter;
        if ([_mothsArray[i] isEqualToString:@"1"]) {
            textLayer.foregroundColor =  [TNColor ff6633Color].CGColor;
        }else{
            textLayer.foregroundColor =  [UIColor lightGrayColor].CGColor;
        }
        
        textLayer.backgroundColor =  [UIColor clearColor].CGColor;
        textLayer.fontSize = 14.0f;
        textLayer.contentsScale = 2;
        [self.layer addSublayer:textLayer];
        textLayer.affineTransform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(angleDegrees));
        [_mothsLabelArray  addObject:textLayer];
    }
}

<img src="http://img.blog.csdn.net/20160601142453744?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" align="middle" alt="" />

相关文章推荐

iOS图形绘制UIBezierPath篇

1、绘制直线UIBezierPath *line = [[UIBezierPath alloc] init]; //设置线宽 line.lineWidth = 3; [line moveToPoint...

iOS图形绘制 UIBezierPath 绘制折线图、柱状图、饼形图

iOS图形绘制 UIBezierPath 绘制折线图、柱状图以及饼形图 三种图表都是属于动态绘制...

iOS-UIBezierPath绘制基本图形

UIBezierPath UIBezierPath可以创建基于矢量的路径,此类是Core Graphics框架关于路径的封装。使用此类可以定义简单的形状,如椭圆、矩形或者有多个直线和曲线段组成的形状...
  • Mazy_ma
  • Mazy_ma
  • 2016年03月17日 13:01
  • 327

OpenPlug Studio应用在iOS的图形绘制效能是Adobe Flash Builder 4.5.1应用的4倍!

(本文转载自http://developer.openplug.com/forum/viewforum.php?sid=7b8a37171b42c540f4bb29c3d43d9e98&lastact...

iOS -- 图形绘制(全)

[转载]IOS图形绘制 CGPATH/CGCONTEXT(转)   原文地址:CGPATH/CGCONTEXT(转)" style="text-decoration:none; color:r...

iOS 绘制简单图形---UIBezierPath篇

****************贝塞尔篇**************** 一、 关于UIBezierPath UIBezierPath这个类在UIKit中, 是Core Graphics框架关于p...

iOS 使用UIBezierPath 绘制图形

这篇文章介绍UIBezierPath的详细的使用, 以及一些细节! 创建一个XTBezierPath集成于UIView的类 使用drawRect 完成图形的绘制 在drawRect方法完成绘...

iOS Quartz2D基本图形绘制(一)

1. Quartz2D简介Quartz2D是二维的绘图引擎(经包装的函数库,方便开发者使用。也就是说苹果帮我们封装了一套绘图的函数库),用Quartz2D写的同一份代码,既可以运行在iphone上又可...

iOS图形绘制方法汇总及图片处理

1、使用UIBezierPath 绘制图形 2.、使用CGContextRef进行图形绘制  http://blog.csdn.net/rhljiayou/article/details/991971...

ios/iphone开发图形绘制,类360 扫描效果

ios/iphone开发图形绘制,类360 扫描效果 (2013-07-16 09:15:15) 跑马灯效果,可变的图片大小下载     官方全面DEMO--QuartzDemo    i...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:iOS UIBezierPath图形绘制
举报原因:
原因补充:

(最多只允许输入30个字)