How to use switch control in iphone?

Leave a Comment
This is the simple demo for switch control in iphone. Here i will give you simple code snippets with source code.

SwitchDemoViewController .h


#import <UIKit/UIKit.h>
@interface SwitchDemoViewController : UIViewController {
UILabel *switchLabel;
UISwitch *toggleSwitch;

}
@property (nonatomic,retain) IBOutlet UILabel *switchLabel;
@property (nonatomic,retain) IBOutlet UISwitch *toggleSwitch;
-(IBAction) switchValueChanged;

@end

SwitchDemoViewController .m

#import "SwitchDemoViewController.h"
@implementation SwitchDemoViewController
@synthesize switchLabel;
@synthesize toggleSwitch;



- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (void)dealloc {
[switchLabel release];
[toggleSwitch release];
    [super dealloc];
}
-(IBAction) switchValueChanged{
if (toggleSwitch.on)
    {
        switchLabel.text = @"ON";
    }
   
else {
        switchLabel.text = @"OFF";
    }
}


@end
This is the very simple example code for switch control.



0 comments:

Post a Comment