iOS-UI-基本控件之UISwitch

UISwitch(开关,默认为关)

IOS开发中必不可少的基本控件,主要用于只有两种的选择,比如飞行模式等等,本文主要是列出常用的属性及方法(注XCode版本为7.2)


//默认状态

iOS-UI-基本控件之UISwitchiOS-UI-基本控件之UISwitch


//属性

@property(nullable, nonatomic, strong) UIColor *onTintColor ;//开着的时候控件的颜色

代码:one.onTintColor=[UIColor brownColor];

如图:

iOS-UI-基本控件之UISwitchiOS-UI-基本控件之UISwitch


@property(null_resettable, nonatomic, strong) UIColor *tintColor ;//感觉像是边框的颜色,并且带有动画,

代码:one.tintColor=[UIColor redColor];

如图:第二张像个动画

iOS-UI-基本控件之UISwitchiOS-UI-基本控件之UISwitch


@property(nullable, nonatomic, strong) UIColor *thumbTintColor ;// 按钮的颜色

代码:

 one.thumbTintColor=[UIColor blueColor];

如图:

iOS-UI-基本控件之UISwitch




@property(nonatomic,getter=isOn) BOOL on;//是否处于开启状态,默认为NO



//方法


- (instancetype)initWithFrame:(CGRect)frame ;      // 设置控件的大小和起始位置


- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder ;//从XIB加载


- (void)setOn:(BOOL)on animated:(BOOL)animated; // 开的时候是否有动画