【问题标题】:Change Popover colors in SWIFT 4在 SWIFT 4 中更改弹出框颜色
【发布时间】:2018-03-11 15:34:31
【问题描述】:

我搜索了一种方法来做到这一点,但没有找到答案!我可以更改按钮的背景颜色,但不能更改箭头颜色。

到目前为止,我已经这样做了:

let alert: UIAlertController    = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alert.view.tintColor            = themeTextColor
alert.view.backgroundColor      = themeDialog

我也试过这个:

alert.popoverPresentationController?.backgroundColor = themeDialog

但它不会改变任何东西。

结果如下:

看到白色区域了吗?

【问题讨论】:

    标签: ios swift uialertcontroller


    【解决方案1】:

    将您的presentationController的背景颜色更改为您想要的颜色。

        public static func newInstance(_ sourceView: UIView) -> PlayerOptionsPopupViewController {
            let controller = PlayerOptionsPopupViewController()
            controller.modalTransitionStyle = .crossDissolve
            controller.modalPresentationStyle = .popover
            if let presentationController = controller.popoverPresentationController {
                    presentationController.delegate = controller
                    presentationController.permittedArrowDirections = arrowDirection
                    presentationController.sourceView = sourceView
                    presentationController.sourceRect = sourceView.bounds
                    presentationController.backgroundColor = UIColor.bsBalloon // Your Color Here
    
             }
            return controller
        }
    
    【解决方案2】:

    您可以在呈现警报视图控制器后更改它的颜色。你要去某个地方,但你需要编写以下代码。

    self.present(alert, animated: true, completion: {
           alert.view.tintColor = UIColor.red
           alert.view.backgroundColor = .green
    })
    

    tintColor 将改变操作按钮的颜色,背景颜色将改变警报视图的背景。

    我希望这对你有用。

    【讨论】:

    • 感谢@Paul 的帮助,但它并没有解决我的问题...我编辑了问题,以便您查看它的外观...背景发生了变化,但就像有后面的其他层我不会改变!
    • 你在设备上试过了吗?
    • 没有改变
    【解决方案3】:

    在呈现的视图控制器中,试试这个……

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    
        if let popoverPresentationController = segue.destination.popoverPresentationController {
            popoverPresentationController.backgroundColor = themeDialog
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-26
      • 2014-02-24
      • 1970-01-01
      • 2013-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多