首页 > 代码库 > 画太极图
画太极图
画太极图
{ 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); }
画太极图
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。