【问题标题】:Change arrow color for popover created from storyboard in Swift更改从 Swift 中的故事板创建的弹出框的箭头颜色
【发布时间】:2016-04-27 07:51:36
【问题描述】:

我正在尝试更改从按钮定义为情节提要 segue(未以编程方式构建)的弹出框的默认弹出框箭头颜色。下图为默认的白色弹出框箭头:

当我添加时

navigationController?.popoverPresentationController?.backgroundColor = myNavBarColor

到弹出框呈现的UIViewControllerviewWillAppear方法,结果如下:

在主UIViewControllerprepareForSegue 方法期间为UIPopoverPresentationController 定义一个新的UIPopoverBackgroundView 类“为时已晚”。

我希望对于这样一个常见的问题会有一个简单的修复(使用与弹出框相同的故事板 segue)。

【问题讨论】:

  • prepareForSegue中设置背景颜色。喜欢这个segue.destinationViewController.popoverPresentationController.backgroundColor
  • 它对我有用,非常感谢! ;)
  • 请注意,我首先必须设置segue.destination.modalPresentationStyle = .popover,否则segue.destination.popoverPresentationController 将是nil。除此之外,解决方案运行良好。

标签: ios swift popover


【解决方案1】:

设置 viewController 的 popoverPresentationController 的背景颜色:

let viewController = YOUR_VIEW_CONTROLLER
viewController.modalPresentationStyle = .popover
if let presentation = viewController.popoverPresentationController {
    presentation.backgroundColor = UIColor.white
}
present(viewController, animated: true, completion: nil)

【讨论】:

    【解决方案2】:

    您也可以将其设置在 popoverPresentationController 中的视图中

    override func viewDidLoad()
    {
        super.viewDidLoad()
        popoverPresentationController?.backgroundColor = view.backgroundColor
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-05
      • 2023-03-14
      • 1970-01-01
      • 2019-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-24
      • 2017-11-06
      相关资源
      最近更新 更多