How to Draw Rectangle In Window Base Application

This is the Simple Example. In this example we will see how to draw rectangle in the window base application.

This is the Simple Example. In this example we will see how to draw rectangle in the window base application.

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

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: Open the RectDrawAppDelegate.m file and make the following changes in the file:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
   
   window.backgroundColor = [UIColor blackColor];
       
        CGRect redFrame = CGRectMake(20, 20, 100, 100);
        UIView *redView = [[UIView alloc] initWithFrame:redFrame];
        redView.backgroundColor = [UIColor redColor];
        [window addSubview:redView];
        [redView release];
       
        CGRect yellowFrame = CGRectMake(120, 120, 100, 100);
        UIView *yellowView = [[UIView alloc] initWithFrame:yellowFrame];
        yellowView.backgroundColor = [UIColor yellowColor];
        [window addSubview:yellowView];
        [yellowView release];
       
        CGRect blueFrame = CGRectMake(220, 220, 100, 100);
        UIView *blueView = [[UIView alloc] initWithFrame:blueFrame];
        blueView.backgroundColor = [UIColor blueColor];
        [window addSubview:blueView];
        [blueView release];
               
        [window makeKeyAndVisible];
       
        return YES;
}

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

You can Download SourceCode from here RectDraw

WP Greet Box icon
Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic, and free programming tips and tricks and source code            snippets.

1 Response » to “How to Draw Rectangle In Window Base Application”

  1. Vinod says:

    Good article, nice and simple.

Leave a Reply

Security Code:

learn iphone programming

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Our Mobile Training Courses

EDUmobile.ORG offers the following 4 Mobile Training Courses. Our iPhone Training Course is very popular, with over 200 developers in training.

learn iphone programming
© 2010 EDUmobile.ORG