Show Text On Label With The Help Of Button in IPhone/iPad

Introduction

In this article we create a single-view application. Here we use one label and three buttons using xib (XCode Interface Builder). In this app, when we click on the first button, the button title color changes and it shows text in the label. The same happens when we click on the second button; the button title color changes and it shows other text in the label, as it is when we click on third button, where again the button title color changes and it shows other text on the label.

Step 1

Open XCode by double-clicking on it.

Select-xcode-in-iphone.jpg

Step 2

Create a New XCode Project via clicking on it.

create-project-in-iphone.jpg

Step 3

Now select "Single View Application" and click on Next.

single-view-application-in-iphone.jpg

Step 4

Now give your Product Name. Here I use UIView and Company Identifier Mcn Solutions and click on Next.

Project-name-in-iPhone.jpg

Step 5

Select the location where you want to save your project and click on Create.

save-project-location-in-iphone.jpg

Step 6

Now you will see in the XCode Window six Objective C Classes generated by XCode. When we use a Single View Application, ViewController automatically generate ViewController.h, ViewController.m class or xib correspondence to iPhone/iPad.

1.Appdelegate.h
2.AppDelegate.m
3.ViewController.h
4.ViewController.m
5.ViewController_iPhone.Xib
6.ViewContoller_iPad.Xib.

Here we write code only in the View Controller class.

ViewController.h

Code-of-ViewController.h-class.jpg

ViewController.m

Code-of-ViewController.m-class.jpg

ViewController_iPhone.Xib

Xib-of-iPhone.jpg

ViewContoller_iPad.Xib

Xib-of-iPad.jpg

Step 7

Click on the File owner icon

File-owner-in-iphone.jpg

Step 8

Connect the button to it's object via linking

connect-Button-to-its-object-via-linking-in-iPhone.jpg


As it is done for iPad:

connection-in-iPad.jpg


Select action touch up inside

Action-in-iPad.jpg


Select  which platform you want to see the output for.

Run-application-in-simulator-in-iphone.jpg

Output

Output 1 in iPhone:

output1-in-iphone.jpg

Output 2 in iPhone:

output2-in-iPhone.jpg

Output 3 in iPhone:

output3-in-iPhone.jpg

Output 4 in iPhone:

output4-in-iPhone.jpg

Output 1 in iPad:

output1-in-iPad.jpg

Output 2 in iPad:

output2-in-iPad.jpg

Output 3 in iPad:

output3-in-iPad.jpg

Output 4 in iPad:

output4-in-iPad.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all