Ios 快速按钮

Ios 快速按钮,ios,swift,swift5,sirishortcuts,Ios,Swift,Swift5,Sirishortcuts,我想制作一个类似快捷方式应用程序的按钮。 一个大按钮和一个小按钮。 小按钮将打开一个新视图,而大按钮仅运行一个简单的打印语句。 如果解决方案是一个豆荚,我会非常高兴,但我认为这并不困难,只是我没有注意:) 我能用这些东西做到这一点: func add(secondButton: UIButton, buttonName: UIButton, secondButtonTitle: String, secondIsEnabled: Bool) { secondButton.isEnabled

我想制作一个类似快捷方式应用程序的按钮。
一个大按钮和一个小按钮。
小按钮将打开一个新视图,而大按钮仅运行一个简单的打印语句。

如果解决方案是一个豆荚,我会非常高兴,但我认为这并不困难,只是我没有注意:)

我能用这些东西做到这一点:

func add(secondButton: UIButton, buttonName: UIButton, secondButtonTitle: String, secondIsEnabled: Bool) {
    secondButton.isEnabled = secondIsEnabled
    print(secondIsEnabled)
    if #available(iOS 13.0, *) {
        secondButton.backgroundColor = UIColor.systemFill
        secondButton.setTitle(secondButtonTitle, for: .normal)
        if buttonName.isEnabled {
            buttonName.backgroundColor = UIColor.systemRed
            buttonName.tintColor = .systemGray4
        } else {
            buttonName.backgroundColor = UIColor.systemOrange
            buttonName.tintColor = .systemGray2
        }
    }else {
        // Fallback on earlier versions
        // TODO: do
        if buttonName.isEnabled {

        } else {
            buttonName.backgroundColor = color
        }
    }
    buttonName.layer.cornerRadius = 4
    view.addSubview(buttonName)

    secondButton.tintColor = .black
    secondButton.frame = CGRect(x: 5.0, y: 5.0, width: 60.0, height: 15.0)
    secondButton.layer.cornerRadius = 4
    buttonName.addSubview(secondButton)
    buttonName.bringSubviewToFront(secondButton)
}
但是如果大按钮被禁用,小按钮也将被禁用

我想保持目前的设计,就是这样 最后一个按钮之所以为红色,是因为它已启用
很抱歉按钮标题是匈牙利语,我忘了翻译,它们只是从1到6的数字

我的问题从这里开始:
在某些情况下,大按钮被禁用。 但我希望始终启用较小的按钮,即使禁用了较大的按钮。
这可能吗?


如果我没有弄错的话,我对谷歌的搜索词将是嵌套的按钮,但我真的找不到任何东西

问题是这行:

buttonName.addSubview(secondButton)

将第二个按钮放在第一个按钮的前面,但不能作为第一个按钮的子视图

问题

 buttonName.addSubview(secondButton)
当大按钮被禁用时,这会导致第二个按钮被禁用。相反,将这两个按钮都添加到主视图的子视图中,然后更改图层属性,使小/秒按钮显示在大按钮的顶部

解决方案

buttonName.layer.zPosition = 0
secondButton.layer.zPosition = 1
view.addSubview(secondButton)

您可以尝试将其创建为包含两个按钮的UIView(buttonsView)

  • 覆盖整个视图的大按钮(主按钮)
  • 带有特定框架的小按钮(第二个按钮)

  • 因此,每当您想禁用大按钮时,可以指定buttonsView.mainButton.isEnabled=false,这样您就可以确保次要按钮不受mainButton状态的影响。请重新构造您的问题。