我想以编程方式将我的 UISwitch 设置为打开或关闭。我该怎么做?我是 iOS 新手。
最佳答案
如果您使用的是 UISwitch,那么正如在开发人员 API 中看到的那样,任务 setOn: animated:
应该可以解决问题。
- (void)setOn:(BOOL)on animated:(BOOL)animated
因此,要在程序中将开关设置为 ON,您可以使用:
Objective-C
[switchName setOn:YES animated:YES];
swift
switchName.setOn(true, animated: true)
https://stackoverflow.com/questions/7799760/