“开” UISwitch的状态 [英] "On" state of a UISwitch

查看:50
本文介绍了“开” UISwitch的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个开关,我想要这样的东西:

I have a switch and I want to have something like this:

override func viewDidLoad() {
    super.viewDidLoad()
    if name.text == "Jack"{
        switch.on = false
    }
}

但是它不起作用!加载视图控制器时,如何更改开关的状态?

But it's not working! How can I change the state of a switch when the view controller is loading?

推荐答案

UISwitch 具有属性 isOn 可以打开和关闭开关。
也不要使用名称 switch ,因为这是Swift中的保留关键字。

UISwitch has a property isOn to turn the switch on and off. Also don't use the name switch since this is a reserved keyword in Swift.

这篇关于“开” UISwitch的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆