DrawRect 图形

 1 DrawRect
 2 
 3 - (void)drawRect:(CGRect)rect
 4 
 5 {
 6 
 7     // Drawing code
 8 
 9     // 当前视图绘制信息
10 
11     CGContextRef context = UIGraphicsGetCurrentContext();
12 
13     // 设置线条的宽度
14 
15     CGContextSetLineWidth(context, 5);
16 
17     // 设置线条的颜色
18 
19     CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
20 
21 //    // 设置线的起点
22 
23 //    CGContextMoveToPoint(context, 0, 0);
24 
25 //    // 设置一条直线(规定线的终点)
26 
27 //    CGContextAddLineToPoint(context, 280, 280);
28 
29 //    // 设置正方形
30 
31 //    CGContextAddRect(context, CGRectMake(20, 20, 240, 240));
32 
33 //   // 根据绘制信息 在视图上绘制图形
34 
35 //    CGContextStrokePath(context);
36 
37     
38 
39     for (int i = 0; i < self.lineArray.count; i++) {
40 
41         NSMutableArray *points = [self. lineArray objectAtIndex:i];
42 
43         if (0 == points.count) {
44 
45             continue;
46 
47         }
48 
49         for (int j = 0; j < points.count - 1; j++) {
50 
51             NSValue *pointValueA = [points objectAtIndex:j];
52 
53             NSValue *pointValueB = [points objectAtIndex:j + 1];
54 
55             
56 
57             CGPoint pointA = [pointValueA CGPointValue];
58 
59             CGPoint pointB = [pointValueB CGPointValue];
60 
61             
62 
63             CGContextMoveToPoint(context, pointA.x, pointA.y);
64 
65             CGContextAddLineToPoint(context, pointB.x, pointB.y);
66 
67         }
68 
69     }
70 
71     CGContextStrokePath(context);
72 
73 }

 

posted @ 2016-06-06 15:24  超级马力  阅读(302)  评论(0)    收藏  举报