標籤:style blog http io ar color os 使用 sp
IOS--UISwitch的使用方法詳細 (2013-08-24 11:09:38)
轉載▼
| 標籤: uiswitch switch 選擇控制項 ios it |
分類: iOS--UI |
// UISwitch的使用
UISwitch *oneSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(20, 20, 0, 0)]; // 預設尺寸為79 * 27。
oneSwitch.backgroundColor = [UIColor greenColor]; // 設定背景色
oneSwitch.alpha = 1.0; // 設定透明度 範圍在0.0-1.0之間 0.0是完全透明
oneSwitch.onTintColor = [UIColor redColor]; // 在oneSwitch開啟的狀態顯示的顏色 預設是blueColor
oneSwitch.tintColor = [UIColor purpleColor]; // 設定關閉狀態的顏色
oneSwitch.thumbTintColor = [UIColor blueColor]; // 設定開關上左右滑動的小圓點的顏色
// oneSwitch.on = YES; // // 設定初始狀態 直接設定為on,你不回觀察到它的變化
[oneSwitch setOn:YES animated:YES]; // 設定初始狀態,與上面的不同是當你看到這個控制項的時候再開始設定為on,你會觀察到他的變化
oneSwitch.onImage = [UIImage imageNamed:@"min.png"]; // 開啟狀態顯示的圖片
oneSwitch.offImage = [UIImage imageNamed:@"max.png"]; // 關閉狀態下的圖片
[oneSwitch addTarget:self action:@selector(oneSwitchValueChanged:)forControlEvents:UIControlEventValueChanged]; // 添加事件監聽器的方法
// 添加到view並釋放記憶體
[self.view addSubview:oneSwitch];
[oneSwitch release], oneSwitch = nil;
#pragma mark - 實現UISwitch監聽的方法
- (void)oneSwitchValueChanged:(UISwitch *) sender {
NSLog(@"%@", sender.isOn ? @"ON" : @"OFF");
}
IOS--UISwitch的使用方法