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

标签 ios swift uibutton uipopover tintcolor

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

 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)
            }
        }
    }

在表格 View 中,我为单元格设置了此设置

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

对于具有相同 View 的所有 6 行也是如此。 这是 prepare(for:)

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

tview 的初始配置是这样的。 initial view state

这是显示弹出窗口的 View 。 the buttons in gray collor when popover presented 那么如何避免弹出窗口中的色调颜色变化呢?

最佳答案

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

关于ios - 在 iOS 中呈现弹出窗口时如何避免按钮色调颜色变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54138595/

相关文章:

iphone - UIImagePickerController - 确定视频是否被修剪或编辑

ios - SpriteKit 在运行带有大型 tilemap (JSTileMap) 的游戏时使用 95-100% CPU

ios - 将应用程序发送到后台并从 XCTest 中的最近应用程序重新启动它

json - Swift JSONSerialization.jsonObject 错误

objective-c - iphone应用程序按钮方法未被调用

iphone - 知道当UILabel的多行属性打开时在哪里拆分字符串

ios - 设置tableview的动态高度

ios - UIViewController initWithNibNamed :bundle: initialized two objects?

ios - UIButton setTitleColor forState 效果很好,而 setTitle 却不行

php - 空白(无)条目在 swift 4 中使用 alamofire 请求插入数据库。请解决它