概述
UISwitch状态切换控件,状态2选1,用BOOL值表示
UISwitch
init
- (instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER; // This class enforces a size appropriate for the control, and so the frame size is ignored.
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
注意:
- initWithFrame中的frame只有frame.origin起作用,frame.size ignored,即UISwitch的size是固定的,不可被定制,size为(51, 31)
appearance
@property(nullable, nonatomic, strong) UIColor *onTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
@property(null_resettable, nonatomic, strong) UIColor *tintColor NS_AVAILABLE_IOS(6_0);
@property(nullable, nonatomic, strong) UIColor *thumbTintColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
@property(nullable, nonatomic, strong) UIImage *onImage NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
@property(nullable, nonatomic, strong) UIImage *offImage NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
注意:
- onTintColor是UISwitch处于on时颜色,不包括圆形颜色,默认绿色
- tintColor是UISwitch处于off时outline(轮廓)颜色,不包括中间区域和圆形颜色,默认白色
- thumbTintColor是UISwitch中间圆形颜色,默认白色
- onImage和offImage在iOS 7及之后无效,iOS 6有效
state
@property(nonatomic,getter=isOn) BOOL on;
- (void)setOn:(BOOL)on animated:(BOOL)animated; // does not send action
event-target-action
UISwitch state changed,UIControlEventValueChanged triggering