CGPoint画直线
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(ctx, point1.x, point1.y);CGContextAddLineToPoint(ctx, point2.x, point2.y); //画 曲线 用CGContextAddArc
CGContextStrokePath(ctx);
完成饼图后,我悲哀的发现,画扇形和画方形、画直线完全是两码事儿,于是不得不重新找资料,完成画长方形,直线和文字的工作。 //画长方形 CGContextRef ctx = UIGraphicsGetCurrentContext(); //画直线,x1和y1是起始点,x2和y2是结束点 //画文字,设置文字内容 [text release]; /// // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code CGContextRefcontext =UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context,2.0); CGContextSetStrokeColorWithColor(context, [[UIColorredColor]CGColor]); CGContextMoveToPoint(context,self.bounds.origin.x,self.bounds.origin.y); CGContextAddLineToPoint(context,self.bounds.size.width,self.bounds.size.height); CGContextStrokePath(context); } |