【问题标题】:How to completely colorize UIPopoverPresentationController background color?如何完全着色 UIPopoverPresentationController 背景颜色?
【发布时间】:2015-11-01 13:42:45
【问题描述】:

我正在为应用程序使用日夜模式。 问题是,当仅设置视图的背景颜色然后将其用作“呈现为弹出框”时,几乎没有白色伪影(见图)

有没有简单的方法来解决这个问题? 我可能需要编写自己的 UIView 吗?

【问题讨论】:

    标签: ios cocoa-touch uiview background-color


    【解决方案1】:

    你可以设置 UIPopoverPresentationController 的backgroundColor。如果这还不够,您将不得不自定义弹出框的UIPopoverBackgroundView。这使您可以控制整个弹出框背景,包括小三角形。

    【讨论】:

    • 对不起,你介意给我一个小例子或指导。我不明白popoverBackgroundViewClass 的意思。在界面生成器中,我的 UIViewController 应该显示为 Popover。我实现了一个继承自 UIPopoverBackgroundView 的类。在另一个视图控制器中是一个通过 segue 调用弹出框的按钮。在“prepareForSegue”方法中,我设置了 config.popoverPresentationController?.popoverBackgroundViewClass = CustomPopoverBackgroundView.self。亲切的问候
    • 它总是因“*** Terminating app due to unaught exception 'NSInternalInconsistencyException' 而崩溃,原因:'-[UIPopoverBackgroundView contentViewInsets] 必须由子类实现。'”。
    • “对不起,你介意给我一个小例子或指导吗”当然:github.com/mattneub/Programming-iOS-Book-Examples/blob/master/…
    • 谢谢。您的示例代码对理解这个问题很有帮助。
    • 设置 popover.backgroundColor = [UIColor clearColor]; 仍然没有为我解决。这比它应该的更难。
    【解决方案2】:

    这里有一些代码来补充马特的答案。

    popoverController.popoverPresentationController?.backgroundColor = myColor
    

    self.navigationController?.popoverPresentationController?.backgroundColor = myColor
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-29
      • 2021-07-02
      • 1970-01-01
      • 2019-12-18
      • 2017-10-04
      • 2018-01-16
      • 2011-05-06
      • 1970-01-01
      相关资源
      最近更新 更多