微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swift - 处理按钮选择的问题

如何解决Swift - 处理按钮选择的问题

我的应用中有一个浮动按钮,可显示 5 个不同的按钮。它们每个都有一种颜色,但最初是灰色的。当用户选择其中一个按钮时,所有按钮都隐藏,当用户再次点击浮动按钮时,之前点击的按钮不是灰色而是具有适当的颜色。

同样的逻辑是用户可以点击另一个按钮来选择它,而前一个将被取消选择,就像用户点击一个选定的按钮一样,它被取消选择。

我将可可豆荚用于浮动按钮 JJFloatingActionButton,但文档中没有关于此的信息。

func configureActionButton() {
    actionButton.overlayView.backgroundColor = UIColor(white: 0,alpha: 0.5)
    actionButton.buttonImage = UIImage(systemName: "line.horizontal.3.decrease")
    actionButton.buttonColor = UIColor(named: "signoColor")!
    actionButton.buttonImageColor = .white
    actionButton.buttonImageSize = CGSize(width: 30,height: 30)
    actionButton.itemAnimationConfiguration = .slideIn(withInterItemSpacing: 14)
    actionButton.itemSizeRatio = CGFloat(0.75)

    let item = actionButton.addItem()
    item.titleLabel.text = "Button 1"
    item.buttonColor = UIColor(red: 254/255.0,green: 224/255.0,blue: 255/255.0,alpha: 1.0)
    item.buttonImageColor = UIColor(red: 200/255.0,green: 73/255.0,blue: 203/255.0,alpha: 1.0)
    item.imageSize = CGSize(width: 30,height: 30)
    item.action = { item in
        //This is for the functionality of the button
    }

    let item2 = actionButton.addItem()
    item2.titleLabel.text = "Button 2"
    item2.buttonColor = UIColor(red: 254/255.0,alpha: 1.0)
    item2.buttonImageColor = UIColor(red: 200/255.0,alpha: 1.0)
    item2.imageSize = CGSize(width: 30,height: 30)
    item2.action = { item in
        //This is for the functionality of the button
    }

    //And I have 3 more buttons

}

这是浮动按钮的样子:

enter image description here

我希望得到一些帮助。我搜索了类似的问题,但没有一个解决了这个问题。谢谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。