How to draw rectangle rectangle rectangle on iphone?

How to draw a rectangle something like this in iphone SDK using basic graphics

Screen Shot of the Crop Tool

+2


source to share


3 answers


These are five rectangles.



You create a CGPath for the dashed rectangle, stroke it, and then create four small CGPaths for the handles and trace around them.

+4


source


Specifically, if you look at the actual iPhone reference documentation for CGPath

, you'll find a section on CGPathAddRect. After that you will probably find the 2D tutorial section on Path Painting .

CGPathAddRect

Adds a rectangle to the editable graphics path.

void CGPathAddRect (
   CGMutablePathRef path,
   const CGAffineTransform *m,
   CGRect rect
);

      

Parameters
path
Modified path of change.

m
Pointer to an affine transformation matrix, or NULL if no transformation is required. If specified, Quartz applies the transform to the rectangle before adding it to the path.



Rectangle The rectangle to
add.

Discussion
This is a handy function that adds a rectangle to a path using the following sequence of operations:

// start at origin
CGPathMoveToPoint (path, m, CGRectGetMinX(rect), CGRectGetMinY(rect));

// add bottom edge
CGPathAddLineToPoint (path, m, CGRectGetMaxX(rect), CGRectGetMinY(rect));

// add right edge
CGPathAddLineToPoint (path, m, CGRectGetMaxX(rect), CGRectGetMaxY(rect);

// add top edge
CGPathAddLineToPoint (path, m, CGRectGetMinX(rect), CGRectGetMaxY(rect));

// add left edge and close
CGPathCloseSubpath (path);

      

Availability
Available on iPhone OS 2.0 and later.

Declared in
CGPath.h

+2


source


I would recommend giving up the pens. They make sense when you are using a mouse; with touch screen, not much.

+2


source







All Articles