In this recipe we will take a look at how easy it is to draw and fill a series of shapes on to the screen.
Following on from our previous recipe, create a new Single View Application, and name it ShapesDrawExample. Create a custom view and name it ShapesView.
To begin, follow these simple steps as outlined in the following order:
Open the
ShapesView.m
implementation file from the Project Navigator window.Modify the
drawRect:
method as shown in the following code snippet.- (void)drawRect:(CGRect)rect { // Set up and initialize our Graphics Context CGContextRef context = UIGraphicsGetCurrentContext(); CGContextClearRect(context, rect); // Draw our Circle to our view CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); CGContextAddEllipseInRect(context, CGRectMake(50,50,150,150)); CGContextFillPath(context); // Draw Square to the Screen CGContextSetFillColorWithColor(context, [UIColor...