views:

319

answers:

2

I would like to draw a line and rectangle in my iPhone application, for that i want to used structure concept to draw line and rectangle.In strut shall i want to be struct line { float X1; float Y1; float X2; float Y3; color of line draw line function };

And similarly in case of rectangle. struct rect { float left X1; float top Y1; float Right X2; float Bottom Y2; color of rectangle; drawRect()//function of draw rectangle };

How i will have to be create the perfect structure for drawing rectangle and lines?

+4  A: 

Obviously, the OP fell victim to automated translation technology.

I suggest you read Quartz 2D Programming Guide for both basic and advanced drawing techniques.

Costique
+1  A: 

UIView has a drawRect: function that is for drawing your content into the specified rectangle. drawRect: does not draw rectangles. Inside drawRect: your drawing calls are rendered to screen otherwise you need to create an offscreen CGContext.

-(void) drawRect:(CGRect)areaRequiringRedraw {
    CGContextRef context = UIGraphicsGetCurrentContext(); // only valid inside drawRect:
    CGRect rect = CGRectMake( x, y, right-x, bottom-y ); // takes width/height not right/bottom
    [[UIColor redColor] setStroke]; // set stroke and fill colors with UIColor
    CGContextStrokeRect( rect ); // outline a rectangle
    CGContextBeginPath( context ); // start a new line
    CGContextMoveToPoint( context , x1 , y1 ); // first point in line
    CGContextAddLineToPoint( context , x2 , y2 ); // add line segments
    CGContextAddLineToPoint( context , x3 , y3 );
    CGContextStrokePath( context ); // draw the line
}
drawnonward