ios画线

 1 - (void)drawRect:(CGRect)rect
 2 {
 3     // Drawing code
 4     [super drawRect:rect];
 5     for(int i=0;i<self.frame.size.height/10;i++)
 6     {
 7     //绘图的上下文
 8     CGContextRef rf=UIGraphicsGetCurrentContext();
 9     //颜色
10     CGContextSetRGBStrokeColor(rf, 255/255.0, .0f, .0f, 1);
11     //线的粗度
12     CGContextSetLineWidth(rf, 1.0f);
13     //线的起始点
14     CGContextMoveToPoint(rf, 0,(i+1)*10);
15     //线的终点
16     CGContextAddLineToPoint(rf, self.frame.size.width,(i+1)*10);
17     CGContextStrokePath(rf);
18     }
19     for (int j=0; j<self.frame.size.width/10; j++) {
20         //绘图的上下文
21         CGContextRef rf=UIGraphicsGetCurrentContext();
22         //颜色
23         CGContextSetRGBStrokeColor(rf, 255/255.0, .0f, .0f, 1);
24         //线的粗度
25         CGContextSetLineWidth(rf, 1.0f);
26         //线的起始点
27         CGContextMoveToPoint(rf, j*10,0);
28         //线的终点
29         if((j+1)*10>self.frame.size.width)
30             continue;
31         CGContextAddLineToPoint(rf, j*10,self.frame.size.height);
32         CGContextStrokePath(rf);
33     }
34 }

创建一个继承自UIView的类  里面会有- (void)drawRect:(CGRect)rect方法     这个还可用来做UILabel的删除线的效果

效果图

posted @ 2013-09-03 21:02  秋等不到夏  阅读(268)  评论(0)    收藏  举报