
The newbie surely search for xCode in the dock. Your are just installed the iPhone SDK it wont get automatically placed in dock. At first we have to run the Xcode IDE from the directory. Xcode runnable file found in the location /Developer/Applications. Once launching the xcode, the xCode icon will be placed in dock but each and every time you restarting the system, the xCode will automatically get removed from dock. So we have to place it permanently in dock. Right Click on Xcode icon present in the dock and select "Keep in Dock".
Step By step process in creating a New Project in Xcode

Creating New Project: (fig 1.1)
After launching the Xcode a pop-up window will appear and shows some detail. For now, just skip that and close it. At the Right top of the desktop the application being selected is Xcode. Now select a File->New Project in the Menu.
(fig 1.1)
Choosing application type:(fig 1.2)
After selecting the new project the window like fig(1.2) appear. There are many type of application that we can develop using xCode.
We will see the difference of all these applications in future post. At beginning
we don't know what type of application we are developing. For sample we take Windows based Application.(Don't check the check box that have given below).
Then press the choose button.
(fig1.2)
Now it will ask to name our application.

The directory structure of our application looks like this(fig 1.3). I have named my application has "MyFirstApplication". The main function and the delegate for our application will automatically generated. Always the class consist of two files SampleClass.h and SampleClass.m. I think most probably you know this. All here we are going to deal with interfaces.
MyFirstApplicationDelegate.h consist of a variable type UIWindow.
this is the mainwindow screen of the iPhone, this is nothing but what we say in general as 'form'.
MyFirstApplicationDelegate.m consist of two functions in default
1. - (void)applicationDidFinishLaunching:(UIApplication *)application { }
2. - (void)dealloc {}
applicationDidFinishLaunching function called while our application getting launched..
So all our coding and placement of views/ controls must be in this function.
dealloc function called while our application getting exited.
Writing Coding to Add Image and a simple Label in the View:
We now trying to write coding to place the Image in iPhone View. At first for that we need an image in our application. Adding the image in our application has been described in the below tow figures fig(1.4) ,fig(1.5) & fig(1.6)
(fig 1.4)

(fig 1.5)
(fig 1.6)
Now the coding we have to write in the applicationDidFinishLaunching function.
UIImageView *imageView=[[UIImageView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
UIImage *image=[UIImage imageNamed:@"Hello World.jpg"];
[imageView setImage:image];
[window addSubview:imageView];
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(100,460,200,20)];
label.text=@"Pavo Feathers";
[window addSubview:label];
[window makeKeyAndVisible];
UIImageView-> This is the view used to place the image in the window.
The syntax for UIImageView initialization is
UIImageView *sampleView=[[UIImageView alloc]
initWithFrame:CGRectMake(float x, float y, float height, float width)];
Maximum for all the Views the initialization is same.
[UIScreen mainScreen].applicationFrame gives the rectangle of the window. In our case now now it returns a rectangle of rect.x=0, rect.y=0, rect.width=320,rect.height=460.
We had chosen a position of the UIImageView. Next we have to Set Image in that imageView.
UIImage *image=[UIImage imageNamed:@"Hello World.jpg"];
the UIImage View class gets the image and keeps the image in the object along with all the properties of the image.
UIImage *image=[UIImage imageNamed:imageName];
setting the image:
[imageView setImage:image];
The ImageView has been created easily now we have to place it in the application window. So adding this view in the application window by
[window addSubview:imageView];
By the same way the label also added in the window. I think for label there is not need of any explanation because it has just initiated and assigned the text.
Some featured links:
Sample Applications for further:
Related Posts by Categories