在这个应用程序中,我希望允许用户更改主菜单的背景颜色。在 MenuVC 中,用户将单击标有“选择颜色”的按钮。'ColorPickerVC' 将以模态方式从 XIB 文件中呈现。
我为此创建了一个 @IBAction 并包含以下代码:
@IBAction func colorPickerPressed = (_ sender: Any) {
let colorPicker = ColorPickerVC()
colorPicker.modalPresentationStyle = .custom
present(colorPicker, animated: false, completion: nil)
}
颜色选择器从 XIB 文件模态加载并以网格格式显示 9 种颜色(UIButton)。
当用户点击一种颜色时,ColorPickerVC 的背景会变为该颜色:
@IBAction func tile1(_ sender: Any) {
view.backgroundColor = tile1Color.backgroundColor
然后用户点击“确认”按钮,这会关闭视图并返回到 MenuVC:
@IBAction func confirmBtnPressed(_ sender: Any) {
dismiss(animated: false, completion: nil)
}
这是我正在努力解决的问题:在“ConfirmBtnPressed”操作期间,我希望 MenuVC 背景颜色也更改为 ColorPickerVC 背景(用户之前选择的颜色)
关于如何实现这一目标的任何想法?
谢谢,斯科特