[英]Change Popover colors in SWIFT 4
I searched for a way to do this but found no answers! 我搜索了一种方法来做,但是没有找到答案! I can change the background color of the buttons, but not the arrow color.
我可以更改按钮的背景颜色,但不能更改箭头颜色。
So far I've done this: 到目前为止,我已经做到了:
let alert: UIAlertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alert.view.tintColor = themeTextColor
alert.view.backgroundColor = themeDialog
I've also tried this: 我也尝试过这个:
alert.popoverPresentationController?.backgroundColor = themeDialog
but it doesn't change anything. 但它并没有改变任何东西。
The result looks like this: 结果看起来像这样:
See the white areas? 看到白色区域?
Change the background color of your presentationController to your desired color. 将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
}
you can change alert view controller colour after presenting it. 您可以在显示后更改警报视图控制器的颜色。 You are going right in somewhere, but you need to write following code.
您正在某个地方前进,但是您需要编写以下代码。
self.present(alert, animated: true, completion: {
alert.view.tintColor = UIColor.red
alert.view.backgroundColor = .green
})
tintColor will change color of action button and background color will change background of alert view. tintColor将更改操作按钮的颜色,背景颜色将更改警报视图的背景。
I hope this will work for you. 希望这对您有用。
In the presenting view controller, try this… 在呈现视图控制器中,尝试此操作…
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let popoverPresentationController = segue.destination.popoverPresentationController {
popoverPresentationController.backgroundColor = themeDialog
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.