iOS - 如何以编程方式设置UISwitch [英] iOS - How to set a UISwitch programmatically
本文介绍了iOS - 如何以编程方式设置UISwitch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以编程方式将我的UISwitch设置为开启或关闭。我该怎么办?我是iOS新手。
I want to set my UISwitch to on or off programmatically. How would I do that? I am an iOS newbie.
推荐答案
我不熟悉iOS中的复选框,但如果您使用的是UISwitch,然后在开发人员API中看到,任务 setOn:animated:
应该可以解决问题。
I'm not familiar with a 'checkbox' in iOS, but if you are using a UISwitch, then as seen in the developer API, the task setOn: animated:
should do the trick.
- (void)setOn:(BOOL)on animated:(BOOL)animated
所以要在你的程序中设置开关,你可以使用:
So to set the switch ON in your program, you would use:
Objective-C
[switchName setOn:YES animated:YES];
Swift
switchName.setOn(true, animated: true)
这篇关于iOS - 如何以编程方式设置UISwitch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文