iOS App

iOS App

In this post we show you how to build a simple iOS application.

Step 1:

Open Xcode, select File ¬> New project ¬> Single view application. click next, Now enter the product name as “show name”, organization name as any name “xyz”, Then organization name will be as “com.xyz”, language as”objective c”, device as “Iphone”.click next and save the project where you want.

Create Project

Create Project

Step 2:

Now go to your project and under general tab.Set the deployment target as iOS 7 and select the orientation as portrait alone. Now click main.storyboard on left side of xcode.Now you will see a black screen.That is called viewcontroller.Click that big screen (navigation controller).In right side of xcode upper part first option” show the file inspector”.Under that uncheck the “use size classes”.Now your viewcontroller will back to normal iphone screen.

ViewController

ViewController

Generally the Xcode has different panels/sections are like toolbar, project navigator,etc. The below image is help full to understand the names and section in Xcode.

Xcode Sections

Xcode Sections

Step 3:

In storyboard , in utility area search for label, text field, button. Now drag one by one and place over the screen. So it should be like below image:

iOS_View_Dev

Now set the button title as “SUBMIT”.

Step 4:

Now go to viewcontroller.h and copy & paste the below code and we will explain what is what.

#import

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UITextField *TextField;
@property (weak, nonatomic) IBOutlet UILabel *NameField;

(IBAction)Ok:(id)sender;
@end

Now Go to storyboard and select the view controller.In side that we have two label, one button, one text field. Now select all and under that debug area. One triangle icon ( resolve Autolayot issues) will be there. Click that and select add missing constraints. So it’s like autolayout. In upcoming chapters you will learn more about auto layout.

Now select the viewcontroller and in utility area select “ show the assistant editor “.It will open one new tab in that select viewcontroller.h. And select the each uielement in viewcontroller and press ctrl + drag to each name . For example , in viewcontroller.h there will be three property and one small dots will be available.Click that textField dot drag and select the text field in viewcontroller.Likewise do for all label,button.

Step 5 :

Go to viewcontroller.m and copy and paste all below code:

#import “ViewController.h”

@interface ViewController ()

@end


@implementation ViewController

@synthesize TextField;

@synthesize NameField;

(void)viewDidLoad { [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib. NameField.hidden = YES;

}

(void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

(IBAction)Ok:(id)sender {

NameField.hidden = NO;

NameField.text = TextField.text;

}

@end

In this above code we have a action method “(IBAction)Ok:(id)sender”. In this we have some code like when user enter some name in text field, that name will be shown in below label.So these are the code explanation:

● Make your Namefield label as hidden at first time
● Set your textfield text is equal to Namefield text
● Keep clean with your code and comment every where.

UI Elements

UI Elements

This above image show like how to connect your code with UI Elements in viewcontroller as we said in step 4.

Step 6 :

Now in tool bar area you see one play button. Press that for run the application and set the iOS device as 5s. Keep remember when you run your application:

● Have you clear all errors
● Have you comment all NSLog statements
● Have you set the device as 5s( whatever device you need)

Now one iphone simulator open and you can enter any name in text field,Then that name will be display in below label.Like blow image:

Testing Result

Testing Result

So this is simple iOS application, with this same application you can design the viewcontroller, You can set the colour and background image for button, label.You can set the keyboard as you want and also you can set the UITextFiled delegate to do some changes in same iOS app.

No Comments

Post a Reply

Inquire Now
close slider