第八篇 - UISwitch

初始化

UISwitch *sw = [[UISwitch alloc] init];

添加事件

[_sw addTarget:self action:@selector(swChange:) forControlEvents:UIControlEventValueChanged];

事件处理

- (void)swChange:(UISwitch *)sw{
    
    if (sw.on) {
        NSLog(@"");
    }else{
        NSLog(@"");
    }
}

 

//
//NS_ASSUME_NONNULL_BEGIN
//
//NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UISwitch : UIControl <NSCoding>
//
//开启状态的颜色
  @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;
//
// 以下两个方法,ios7后不再生效
  @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;
//
// 设置开关状态,没有动画(主要用来判断状态,设置开关状态,用下面的)
  @property(nonatomic,getter=isOn) BOOL on;
//
  - (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;
//
//设置开关状态
  - (void)setOn:(BOOL)on animated:(BOOL)animated; // does not send action
//
  @end

 

posted @ 2016-03-17 16:38  人生路1/5  阅读(182)  评论(0编辑  收藏  举报