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); } |
本文介绍如何使用Core Graphics在iOS应用中绘制长方形、直线及文字。通过设置颜色、线宽等属性,实现基本图形的绘制,并展示具体代码实现。
638

被折叠的 条评论
为什么被折叠?



