How to completely colorize UIPopoverPresentationController background color?
Asked Answered
W

2

17

I'm working with a Day and Night Mode for an app. The problem is, when just setting the background color of a view AND THEN using it as "presenting as popover" there are little white artifacts (see the picture)

Is there an easy way to fix this? Do I may have to write my own UIView?

enter image description here

Winegrower answered 9/8, 2015 at 15:54 Comment(0)
A
16

You can set the UIPopoverPresentationController's backgroundColor. If that isn't sufficient, you will have to customize your popover's UIPopoverBackgroundView. This gives you control of the entire popover background, including the little triangle.

Assign answered 9/8, 2015 at 16:0 Comment(5)
Sorry, would you mind giving me a little example or guide. I didn't got the point with the popoverBackgroundViewClass. In the Interface Builder I have my UIViewController which should be displayed as Popover. I implemented a class which inherits from UIPopoverBackgroundView. In another view controller is a button which calls the popover by segue. In the "prepareForSegue" method I am settings config.popoverPresentationController?.popoverBackgroundViewClass = CustomPopoverBackgroundView.self. Kind regardsWinegrower
It always crashes with "*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIPopoverBackgroundView contentViewInsets] must be implemented by subclassers.'".Winegrower
"Sorry, would you mind giving me a little example or guide" Sure: github.com/mattneub/Programming-iOS-Book-Examples/blob/master/…Assign
Thank you. Your sample code helped very much to understand this matter.Winegrower
Setting popover.backgroundColor = [UIColor clearColor]; still didn't fix it for me. This is harder than it should be.Inhalant
C
2

Here is some code to supplement matt's answer.

popoverController.popoverPresentationController?.backgroundColor = myColor

or

self.navigationController?.popoverPresentationController?.backgroundColor = myColor
Clamshell answered 6/8, 2016 at 2:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.