如何保存按钮状态

时间:2020-08-28 22:38:22

标签: swift uibutton

我的详细信息视图控制器中有4个按钮,可将其推入具有不同数据的同一视图控制器。我的问题是,作为一个初学者,我真的不知道如何保存每个项目的按钮状态。

这是我其中一个按钮的代码


 @IBAction func addToWatchlistButtonPressed(_ sender: UIButton) {
        if Auth.auth().currentUser == nil {
            let vc = self.storyboard?.instantiateViewController(identifier: K.ViewControllerName.signupVC) as! SignUpViewController
            self.present(vc, animated: true, completion: nil)
        }else {
            sender.isSelected = !addToWatchlistButton.isSelected
            if addToWatchlistButton.isSelected {
                addToWatchlist()
                print("selected")
                self.addToWatchlistButton.backgroundColor = .clear
                    self.addToWatchlistButton.tintColor = .clear
                    self.addToWatchlistButton.setTitleColor(UIColor(named: K.UIColors.label), for: .selected)
                    self.addToWatchlistButton.setTitle("Added to Watchlist", for: .selected)
                    self.addToWatchlistButton.layer.borderWidth = 2
                    self.addToWatchlistButton.layer.borderColor = CGColor(srgbRed: 251/255, green: 172/255, blue: 14/255, alpha: 1)
            }else {
                removeFromWatchlist()
                print("deselected")
                self.addToWatchlistButton.backgroundColor = UIColor(named: K.UIColors.button)
            self.addToWatchlistButton.tintColor = UIColor(named: K.UIColors.label)
            }
        }
    }

0 个答案:

没有答案