在 UITableView 上按下时 UIButton 不会改变其状态

水晶

在 UITableView 上添加 UIButton 时有什么不同吗?或者是我添加 UIButton 的代码不正确导致按钮看起来不像它被选中

    let addStudentButton = UIButton()
    addStudentButton.translatesAutoresizingMaskIntoConstraints = false
    let views = ["addStudentButton": addStudentButton]
    var allConstraints = [NSLayoutConstraint]()
    addStudentButton.setTitle("hi", for: .normal)
    //        addStudentButton.addTarget(self, action: #selector(StudentsViewController.addStudent), for: UIControlEvents.touchUpInside)
    addStudentButton.titleLabel?.font = UIFont.systemFont(ofSize: 20.0)
    addStudentButton.setTitleColor(UIColor.flatWhite(), for: .normal)
    addStudentButton.setTitleColor(UIColor.flatWhite(), for: .selected)
    addStudentButton.layer.backgroundColor = UIColor.flatForestGreen().cgColor
    addStudentButton.layer.shadowRadius = 4.0
    addStudentButton.layer.shadowOpacity = 0.8
    addStudentButton.layer.shadowOffset = CGSize(width: 0, height: 1)
    allConstraints += NSLayoutConstraint.constraints(withVisualFormat: "H:[addStudentButton(>=44)]", options: [], metrics: nil, views: views)
    allConstraints += NSLayoutConstraint.constraints(withVisualFormat: "V:[addStudentButton(>=44)]", options: [], metrics: nil, views: views)
    NSLayoutConstraint.activate(allConstraints)
    studentsTableView.addSubview(addStudentButton)

    addStudentButton.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor, constant: -8.0).isActive = true
    addStudentButton.rightAnchor.constraint(equalTo: view.layoutMarginsGuide.rightAnchor, constant: 0.0).isActive = true

我基本上有一个列出学生的 UITableView,我想要一个位于屏幕右下角的按钮,该按钮位于可以选择的 UITableView 顶部。该按钮看起来很好,直到我按下它然后它永远不会有文本改变颜色和内容的选定外观。

哑光

问题是:

  • let addStudentButton = UIButton()制作一个.custom按钮,点击该按钮不会自动更改

  • 您的标题颜色对于所有州都是相同的,因此无论如何都要特别防止标题颜色的任何更改

  • 轻按的按钮突出显示,未选中

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章