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

简单同心圆效果

时间:2015-11-28 18:01:56      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

 1 #import "BNRHypnosisView.h"
 2 
 3 @implementation BNRHypnosisView
 4 - (instancetype)initWithFrame:(CGRect)frame
 5 {
 6     self = [super initWithFrame:frame];
 7     if(self)
 8     {
 9         self.backgroundColor = [UIColor clearColor];
10     }
11     return  self;
12 }
13 - (void)drawRect:(CGRect)rect
14 {
15     CGRect bounds = self.bounds;
16     
17     //根据bounds 计算中心点
18     CGPoint center;
19     center.x = bounds.origin.x + bounds.size.width / 2.0;
20     center.y = bounds.origin.y + bounds.size.height/ 2.0;
21     
22     //根据视图宽和高 中的较小值计算圆形的半径
23 //    float radius = (MIN(bounds.size.width, bounds.size.height)) / 2.0;
24     
25     //使最外层圆形成为视图的外接圆
26     float maxRadius = hypot(bounds.size.width, bounds.size.height)/2.0;
27     
28     //该对象用于绘制直线或曲线,从而组成各种形状。
29     UIBezierPath *path = [[UIBezierPath alloc]init];
30     //以中心点为圆心,radius 的值为半径,定义一个0 到m_PI *2.0弧度的路径(整圆)
31 //    [path addArcWithCenter:center
32 //                    radius:radius
33 //                startAngle:0.0
34 //                  endAngle:M_PI * 2.0
35 //                 clockwise:YES];
36     
37     for(float currentRadius = maxRadius; currentRadius >0; currentRadius -= 20)
38     {
39      //原始的同心圆会产生一个绘制时出现的笔迹,需要将它移除
40         [path moveToPoint:(CGPoint){center.x + currentRadius,center.y}];
41         [path addArcWithCenter:center
42                         radius:currentRadius
43                     startAngle:0.0
44                       endAngle:M_PI*2.0
45                      clockwise:YES];
46     }
47     
48     //设置线条宽度为10点
49     path.lineWidth = 10;
50     
51     //设置绘制颜色为浅灰色
52     [[UIColor redColor] setStroke];
53     
54     [path stroke];
55 }

 

简单同心圆效果

标签:

原文地址:http://www.cnblogs.com/yanggenwei/p/5002975.html

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