概述
-UISwitch
提供二進(jìn)制選項(xiàng)的控件傻咖,如開/關(guān)景东。
-UISwitch
繼承自UIControl
屬性和方法
初始化方法(iOS 系統(tǒng)內(nèi)置了UISwithch控件的size,所以通過代碼調(diào)整UISwithch
的大小無效.默認(rèn)大小 51.0f 31.0f)
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 100, 30)];
設(shè)置初始狀態(tài)(默認(rèn)狀態(tài)為NO
)
mySwitch.on = YES;
設(shè)置按鈕處于關(guān)閉狀態(tài)時(shí)邊框的顏色
mySwitch.tintColor = [UIColor redColor];
設(shè)置開關(guān)處于開啟時(shí)的狀態(tài)
mySwitch.onTintColor = [UIColor blackColor];
設(shè)置開關(guān)的狀態(tài)鈕顏色
mySwitch.thumbTintColor = [UIColor blueColor];
在iOS 6及更早版本中,當(dāng)開關(guān)處于打開位置時(shí)顯示圖像租冠。在iOS 7以后茄螃,設(shè)置無效
mySwitch.onImage = [UIImage imageNamed:@"驗(yàn)證碼"];
在iOS 6和更早版本中雪猪,當(dāng)開關(guān)處于關(guān)閉位置時(shí)顯示圖像慈俯。在iOS 7以后渤刃,設(shè)置無效
mySwitch.offImage = [UIImage imageNamed:@"驗(yàn)證碼"];
整個(gè)開關(guān)背景色,設(shè)置后可以明顯看到一個(gè)矩形背景
mySwitch.backgroundColor = [UIColor redColor];
添加點(diǎn)擊事件
[mySwitch addTarget:self action:@selector(valueChanged:) forControlEvents:(UIControlEventValueChanged)];