IBOutlet UISwitch *switcher; if(switcher.isOn) { lblResult.text = @"Switch is On"; } else { lblResult.text = @"Switch is Off"; }
IBOutlet UISwitch *switcher; [switcher setOn:YES]; [switcher setOn:NO];
- (IBAction)switchChanged:(id)sender { UISwitch *switcher = (UISwitch *)sender; if(switcher.isOn) { lblResult.text = @"Switch is On"; } else { lblResult.text = @"Switch is Off"; } }
- (IBAction)setToOn:(id)sender { [switchItem setOn:YES]; lblResult.text = @"Switch is On"; } - (IBAction)setToOff:(id)sender { [switchItem setOn:NO]; lblResult.text = @"Switch is Off"; }
// // ViewController.h // switchApp // // Created by Weerachai on 11/10/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController { IBOutlet UILabel *lblResult; IBOutlet UISwitch *switchItem; } - (IBAction)switchChanged:(id)sender; - (IBAction)setToOn:(id)sender; - (IBAction)setToOff:(id)sender; @end
// // ViewController.m // switchApp // // Created by Weerachai on 11/10/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)switchChanged:(id)sender { UISwitch *switcher = (UISwitch *)sender; if(switcher.isOn) { lblResult.text = @"Switch is On"; } else { lblResult.text = @"Switch is Off"; } } - (IBAction)setToOn:(id)sender { [switchItem setOn:YES]; lblResult.text = @"Switch is On"; } - (IBAction)setToOff:(id)sender { [switchItem setOn:NO]; lblResult.text = @"Switch is Off"; } - (void)dealloc { [lblResult release]; [switchItem release]; [super dealloc]; } @end
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท