iPhone App Programming

“Hello world”

One of the most simple and called as first computer program to display just “hello world” on screen. So before moving to Advanced App Development let us start from the basic i.e. to write a program to print “hello world” on iPhone (simulator) Screen.

NOTE: Before moving please make sure that you have read the basic of iOS programming and if not then click here to see.

Here we go, our Aim of program is to print “hello world ” on screen. looks simple is’nt it and yes it is..!!

Generally there is few ways to print the hello world on screen/console like by using label, text boxes, core text etc but in this post i am going to use the UILABEL which is simple and easily understood.

There is two way to put UILABEL on Screen.

  1. Using Apple interface builder tool to just drag and drop the control (same as VB).
  2. By using code section to manually code the UILABEL (we are using this in post).

Step 1: Open the Xcode that you have installed.

After opening following prompt screen would come on screen.

Prompt Screen

Create a new project by clicking on Create a new Xcode Project on prompt screen.

Step2:

As our Aim to print the hello world on screen the SDK provides us many inbuilt templates to use as per the nature of App as shown in screen.

Templates

here select the View – Based Application which will give you enough code for the simple view of screen. After selecting the View – based Application click on Next now next window appear  and asks you to insert some project information.

project - information

Here is the little description of the info:

Product Name: name of app (anything).

Company Identifier: this is the unique ID used to identify your company. It is generated as per your product name.

Device family: Selection of platform where the App is gonna run.

Once fill out the information click next and it will lead you to code window.

Step3: Code

Here is the code to print “Hello world” on screen.

  1. (void)viewDidLoad {
  2. [super viewDidLoad];
  3. CGRect frame = CGRectMake(10, 10, 300, 25);
  4. UILabel *helloLabel = [[UILabel alloc] initWithFrame:frame];
  5. helloLabel.text = @”Hello iPhone!”;
  6. helloLabel.textColor = [UIColor blueColor];
  7. helloLabel.textAlignment = UITextAlignmentCenter;
  8. [self.view addSubview:helloLabel];
  9. [helloLabel release];
  10. }

Explanation:

Line 4: This line creates a frame with x and y parameter passed in it.

Line 5: This line creates a UILABEL object by assigning some memory by using alloc( same as ‘C’ function).

Lines 6-8: In these lines we used to configure the UILABEL parameters by providing different property like alignment, color etc.

Line 9: This line gets the label to display the text on screen.

Line 10: Garbage collection ( same as JAVA).

Step5: Running the Application

Now all have done you need to just run the program to do that select iPhone simulator from top menu of Xcode and select Run.

Your will be compiled and start in few moments.

Output should look like this:

Hope this post would help to beginners to start the iOS programming. if you want the complete source code with all the configurations then click on download button to get it.

Hope this post will help you , waiting for good feedback in form of comments and like.

Enjoyyy and good luck.

Happy Programming..

 

About Shahid

Shahid is a Engineering student and addicted to Technology. He is Working For iTechCode(Editor-In-Chief) very passionate about blogging and technology. His area of interest includes programming, tech gadgets, gaming, internet marketing, blogging etc.

Comments

  1. Kingsley Felix says:

    Nice One….You are really doing a gr8 job keep it up.

Speak Your Mind

*