UISwitch简单介绍

UISwitch是个好东西,话不多说,上代码

    UISwitch *switchButton = [[UISwitch alloc] initWithFrame:CGRectMake(50, 100, 0, 0)];
    [switchButton setOn:YES];
    [switchButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:switchButton];
    [switchButton release];

-(void)switchAction:(id)sender
{
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn) {
        NSLog(@"开关打开");
    }else {
        NSLog(@"开关关闭");
    }
}

 

 

posted @ 2013-08-17 10:07  15.10  阅读(179)  评论(0编辑  收藏  举报