UISwithch属性说明:
tintcolor
:开关处于关闭状态时的颜色 onTintcolor
:开关处于开启状态时的颜色 thumbTintcolor
:开关的状态钮颜色 onImage
:开关处于开启状态时的图片(iOS7及之后设置无效) offImage
:开关处于关闭状态时的图片(iOS7及之后设置无效) backgroundcolor
:整个开关背景色,设置后可以明显看到一个矩形背景 iOS系统内置了UISwithch控件的size,所以通过代码调整UISwithch的大小无效.
oc代码:
- (voID)vIEwDIDLoad {[super vIEwDIDLoad];self.mSwitch.tintcolor = [UIcolor redcolor];self.mSwitch.onTintcolor = [UIcolor blackcolor];self.mSwitch.thumbTintcolor = [UIcolor yellowcolor];self.mSwitch.backgroundcolor = [UIcolor purplecolor];//iOS7&later设置无效self.mSwitch.onImage = [UIImage imagenamed:@"on"];self.mSwitch.offImage = [UIImage imagenamed:@"off"];//设置无效UISwitch *s = [[UISwitch alloc]initWithFrame:CGRectMake(100,100,200,200)];[self.vIEw addSubvIEw:s];}- (IBAction)switchValueDIDChanged:(UISwitch *)sender {NSLog(@"%@",sender.isOn?@"switch is On":@"switch is Off");}
swift代码:
@IBOutlet weak var mSwitch: UISwitch!overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() self.mSwitch.tintcolor = UIcolor.redcolor() self.mSwitch.onTintcolor = UIcolor .yellowcolor() self.mSwitch.thumbTintcolor = UIcolor.bluecolor() self.mSwitch.backgroundcolor = UIcolor.clearcolor() var sw = UISwitch(frame: CGRectMake(0,0)) sw.addTarget(self,action: "switchValueDIDChanged",forControlEvents: UIControlEvents.ValueChanged) self.vIEw.addSubvIEw(sw)}@IBAction func switchValueDIDChanged(sender: UISwitch) { var result = sender.on ? "on" : "off" println("switch is \(result)")}总结
以上是内存溢出为你收集整理的自定义UISwitch颜色全部内容,希望文章能够帮你解决自定义UISwitch颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)