UISwitch

    //开关    不用设置宽高  有默认宽高

    UISwitch * sw = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 0, 0)];

    //开关的状态

    sw.on = YES;

    //开关打开时的颜色

    sw.onTintColor = [UIColor redColor];

    //开关关闭时的颜色

    sw.tintColor = [UIColor cyanColor];

    //开关圆圈的颜色

    sw.thumbTintColor = [UIColor yellowColor];

    //适用于iOS6.0

    //    sw.onImage = [UIImage imageNamed:@"onimage"];

    //    sw.offImage = [UIImage imageNamed:@"onimage"];

    

    //UIControlEventValueChanged  事件选择

    

    [sw addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];

    

    [self.view addSubview:sw];   

}

- (void)switchAction:(UISwitch *)sw {

    

    if (sw.on) {

        self.switchLabel.hidden = NO;

    } else {

        self.switchLabel.hidden = YES;

    }

}