How to use UISwitch in Objective c?


This tutorial deals with how to use UISwitch in objective c for iPhone

Let the viewController class be toggleswitchViewController

Open toggleswitchViewController.xib file

Add a UISwitch and  a UILabel as shown below

 

 

Now come to coding part

In toggleswitchViewController.h file

add the following code

 

 

Now come to toggleswitchViewController.m file

add the following highlighted lines of code

 

 

Save all the above work

Now come to toggleswitchViewController.xib again

Make connections as shown in figure

 

 

 

Now save and run the project

Output

When switch is on label shows enabled and when switch is off label shows disabled