码迷,mamicode.com
首页 > 其他好文 > 详细

画太极图

时间:2014-12-09 15:45:51      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:ios

画太极图

{
    CGFloat _degree;//表示当前的角度
    CGFloat _r;//表示半径
    CGFloat _R;//view的宽度/2
    CGFloat _eye;//孔
}

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        _degree = 30;
        _r = frame.size.width/2 - 1;
        _R = frame.size.width/2;
        _eye = _r/6;//小圆
    }
    return self;
}

float degreeToRadian(float degree) {
    return  M_PI / 180 * degree;
}

- (void)drawRect:(CGRect)rect {
    CGContextRef crf = UIGraphicsGetCurrentContext();
    CGContextAddEllipseInRect(crf, CGRectMake(1, 1, _r * 2, _r * 2));
    CGContextStrokePath(crf);
    //右上角的半圆
    CGContextAddArc(crf, _R + _r * cos(degreeToRadian(_degree))/2, _R - _r * sin(degreeToRadian(_degree))/2, _r/2, degreeToRadian(-_degree), degreeToRadian(-_degree + 180), 0);
    //左下角的半圆
    CGContextAddArc(crf, _R - _r * cos(degreeToRadian(_degree))/2, _R + _r * sin(degreeToRadian(_degree))/2, _r/2, degreeToRadian(-_degree), degreeToRadian(-_degree + 180), 1);
    //大圆,回到起点
    CGContextAddArc(crf, _R, _R, _r, degreeToRadian(-_degree + 180), degreeToRadian(-_degree), 1);
    
    CGContextAddEllipseInRect(crf, CGRectMake(_R + _r * cos(degreeToRadian(_degree))/2 - _eye, _R - _r * sin(degreeToRadian(_degree))/2 - _eye, _eye * 2, _eye * 2));
    CGContextAddEllipseInRect(crf, CGRectMake(_R - _r * cos(degreeToRadian(_degree))/2 - _eye, _R + _r *sin(degreeToRadian(_degree))/2 - _eye, _eye * 2, _eye * 2));
    CGContextFillPath(crf);
}


画太极图

标签:ios

原文地址:http://blog.csdn.net/rainlesvio/article/details/41823481

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!