一、簡(jiǎn)介
<<UISwitch 的作用是給用戶提供開(kāi)關(guān),在系統(tǒng)的設(shè)置界面很常見(jiàn)
<<繼承關(guān)系:UISwitch-->UIControl-->UIView-->UIResponder-->NSObject
格式為
1-->設(shè)置開(kāi)狀態(tài)下的顏色(作用)
switch.onTintColor = [UIColor yellowColor]; (這是具體的例子)
@property(nullable, nonatomic, strong) UIColor *onTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;(這是說(shuō)明)
二、UISwitch的屬性(屬性的順序與蘋(píng)果API一致)
1--> 設(shè)置開(kāi)狀態(tài)下的顏色
switch.onTintColor = [UIColor yellowColor];
@property(nullable, nonatomic, strong) UIColor *onTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
2-->設(shè)置關(guān)狀態(tài)下的背景顏色
switch.tintColor = [UIColor redColor];
@property(null_resettable, nonatomic, strong) UIColor *tintColor NS_AVAILABLE_IOS(6_0);
3-->設(shè)置滑塊的背景顏色
switch.thumbTintColor = [UIColor blueColor];
@property(nullable, nonatomic, strong) UIColor *thumbTintColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
4-->設(shè)置開(kāi)關(guān)處于開(kāi)啟狀態(tài)時(shí)的圖片(iOS7及之后設(shè)置無(wú)效)
switch.onImage = [UIImage imageNamed:@"on.png"];
@property(nullable, nonatomic, strong) UIImage *onImage NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
5-->設(shè)置開(kāi)關(guān)處于關(guān)閉狀態(tài)時(shí)的圖片(iOS7及之后設(shè)置無(wú)效)
switch.offImage = [UIImage imageNamed:@"off.png"];
@property(nullable, nonatomic, strong) UIImage *offImage NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
6--> 設(shè)置switch的開(kāi)關(guān)
swith.on = YES;
@property(nonatomic,getter=isOn) BOOL on;
7-->初始化方法
UISwitch *switchButton = [[UISwitch alloc] initWithFrame:CGRectMake(50, 100, 20, 10)];
-(instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER;
8-->初始化方法
-(nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
9-->設(shè)置開(kāi)關(guān)狀態(tài)
[switch2 setOn:YES animated:YES]
-(void)setOn:(BOOL)on animated:(BOOL)animated;