在 iOS 中呈现弹出窗口时如何避免按钮色调颜色变化?

How to avoid button tint color change when presenting a popover in iOS?

我有一个全屏显示弹出窗口的按钮,主视图有 6 个自定义视图,其中 5 个按钮的色调颜色为灰色或蓝色,具体取决于某些参数。但是当弹出窗口出现时,海关视图内的按钮变为灰色,一旦弹出窗口消失,自定义视图得到的是色调颜色,我想避免当弹出窗口出现时,按钮色调 conlor 不会改变。 自定义视图是 UITableviewCell 中的一个视图。自定义视图定义为这样。

 class ratingDoors: UIView {
    var rating: Int = 0{
        didSet{
            makeRating()
        }
    }

    @IBOutlet var contentView: UIView!
    @IBOutlet weak var button1: UIButton!
    @IBOutlet weak var button2: UIButton!
    @IBOutlet weak var button3: UIButton!
    @IBOutlet weak var button4: UIButton!
    @IBOutlet weak var button5: UIButton!

    override init(frame: CGRect) {
        super.init(frame: frame)
        commonInit()
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        commonInit()
        //fatalError("init(coder:) has not been implemented")
    }
    private func commonInit() {
        //TODO: Do some stuff
        // 1. Load the nib
        Bundle.main.loadNibNamed("ratingDoors", owner: self, options: nil)

        // 2. Add the 'contentView' to self
        addSubview(contentView)
        contentView.frame = self.bounds
        contentView.autoresizingMask = [.flexibleHeight,.flexibleWidth]
    }

    @IBAction func setRating(sender: UIButton){
        rating = sender.tag
        //makeRating()
    }
    func makeRating() {
        button1.configureRatingButton(i: rating)
        button2.configureRatingButton(i: rating)
        button3.configureRatingButton(i: rating)
        button4.configureRatingButton(i: rating)
        button5.configureRatingButton(i: rating)
    }
    }

    extension UIButton{
        func configureRatingButton(i: Int){
            if self.tag <= i {
                self.tintColor = UIColor(red: 90/255, green: 212/255, blue: 227/255, alpha: 1.0)
            }else{
                self.tintColor = UIColor(red: 204/255, green: 204/255, blue: 204/255, alpha: 1)
            }
        }
    }

在表格视图中,我对单元格进行了此设置

let cell = tableView.dequeueReusableCell(withIdentifier: "ratingCell") as! ratingTableViewCell
        cell.ratingLabel.text = "Ordenado"
            if let ordered = requestManager.instance.user.ordered{
                cell.ratingView.rating = ordered
            }

        return cell

对于具有相同视图的所有 6 行等等。 这是 prepare(for:)

let popoverVC = segue.destination as! popoverViewController
        popoverVC.delegate = self
        popoverVC.modalPresentationStyle = UIModalPresentationStyle.popover
        popoverVC.popoverPresentationController!.delegate = self

tview 的初始配置是这样的。

这是显示弹出窗口的视图。 那么如何避免弹出窗口中的色调变化呢?

如果您将每个按钮的 tintAdjustmentMode 设置为 .normal,它们将不会在显示弹出窗口时调整色调。另一种选择是使用不响应色调变化的自定义按钮类型(而不是系统)。