1.自定义一个 CustomView : UIView类,该类继承自 UIView,当然也可以继承自UIView的子类,比如 UIScrollView
2.在CustomView中重写下面的方法,这个方法中的内容绘制代码,可以参考 iphone Quartz 2D 开发指南.
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 2.0);
for(int idx = 0; idx < self.points.count; idx++)
{
point = [self.points objectAtIndex:idx];//Edited
if(idx == 0)
{
// move to the first point
CGContextMoveToPoint(context, point.x, point.y);
}
else
{
CGContextAddLineToPoint(context, point.x, point.y);
}
}
CGContextStrokePath(context);
}
3.在xib中的拖动一个UIView到界面中,将这个UIView的 Class属性设置成 CustomView即可.