//公开手机号的开关 UISwitch * phoneSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(bgimage.width-95, (50.0f-30.0f)/2+1, 50, 30)]; phoneSwitch.on = YES; [phoneSwitch addTarget:self action:@selector(switchIsChange:) forControlEvents:UIControlEventValueChanged]; [bgimage addSubview:phoneSwitch]; [phoneSwitch release]; //UISwitch继承自UIControl,能够经过UISwitch的ison方法,来判断它是不是选中的。