【问题标题】:Creat UIButton that activate UISwitch [closed]创建激活 UISwitch 的 UIButton [关闭]
【发布时间】:2023-10-06 10:00:01
【问题描述】:

正如标题所说;我如何创建一个激活 UISwitch 的 UIButton,如果它已经打开,然后停用它..?

【问题讨论】:

  • 您有什么具体问题/疑问?
  • 我不知道该怎么做

标签: objective-c uibutton uiswitch


【解决方案1】:

假设你有一个

IBOutlet UISwitch * myNiceSwitch;

您可以将一个按钮 (UIButton) 放到您的视图中,并将其连接到 IBAction,然后激活(或者在我的情况下,切换)您的 UISwitch:

- (IBAction) pushButtonAction: (id) sender
{
    BOOL switchEnabled = myNiceSwitch.enabled;

    myNiceSwitch.enabled = !switchEnabled;
}

应该就这么简单吧?

【讨论】:

  • 它的工作,感谢您的帮助!