Draw Circle Triangle And Rectangle in iPad

Draw Circle Triangle And Rectangle in iPad

This is the very simple tutorial. In this tutorial we will see how to draw Circle, Triangle and  Rectangle in the iPad.

Step 1: Create a Window base application using template. Give the application name “ThreeViews”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: We need to add  one UIView file in the project. Select classes-> New File -> Add ->Cocoa Touch Class -> Select Objective C class -> Subclass of -> UIView. Give the class name “CircleView”.

Step 4: Open the ThreeViewsAppDelegate.m file and make the following changes in the file:




Step 5: Open the CicleView.m file and make the following changes in the drawRect: method.




Step 6: Now compile and run the application in the Simulator.

You can Download SourceCode from here ThreeViews

Comments 10

  1. No need to import CircleView.h file in the ThreeViewsAppDelegate.h file, only define in the ThreeViewsAppDelegate.m file.

  2. > CGContextRef ctx = UIGraphicsGetCurrentContext();

    I get no warning, no errors… but CGContextRef is always NULL.

    Why are both of these needed, instead of just 1:
    > CGContextRef contextRef = UIGraphicsGetCurrentContext();
    > CGContextRef ctx = UIGraphicsGetCurrentContext();
    Do they point to 2 different things?

  3. You’d better use CGContextAddArc() with startAngle=0 and endAngle=2*pi if you want a real round circle. Sample code:


Leave a Reply

Your email address will not be published. Required fields are marked *