How to change UIPopoverPresentationController's arrow color without drawing my own - ios

I want to change the color of the arrow that UIPopoverPresentationController uses to point at its source. The only way I can see to do this is to subclass UIPopoverBackgroundView and write drawRect and draw the popover border and arrow myself. That's a pain, because there are little niceties in the default popover like rounded corners on everything. And I want to make it feel as much at home on the platform as I can.
Do I really have to draw my own popover arrow just to change the color of the arrow?
Update: I've tried setting the backgroundColor of the UIPopoverPresentationController, but it appears to change the color of everywhere the arrow might draw. I've seen it work before, but I can't nail down what makes it work when it does. See screenshot of setting the color to red. The blue is the content of the navigation controller in the popover. It's supposed to be pointing at the button.

The UIPopoverPresentationController's backgroundColor property should handle that for you
Update
I've used this approach a number of times and have never seen what you have in your screenshot. Are you sure you are using popoverPresentationController.backgroundColor and not setting a different background color on a view or container? Below is screenshot of non-centered popover arrow. The view controller background is green, the popoverPresentationController.backgroundColor is red. Shown next to the code setting the value.
Update #2
I looked at the project you posted and found the problem (although I'm not entirely sure why it's the problem). You are setting the popover presentation controller's backgroundColor property inside your presented view controller under viewWillAppear:. I suspect that setting the background color like this after the presentation happened is what triggers the bug pre-iOS 10.
If you set the popover presentation controller's backgroundColor inside your presenting view controller's onPopover: method, where you are also setting the sourceView and sourceRect properties (and before you actually call presentViewController:), everything works correctly.

Related

Changing the iOS 13 UIPopoverPresentationController blur and shadow amount?

The appearance of the modal popover view shown by the UIPopoverPresentationController in iOS 13 has changed significantly from how it looked in iOS 12. The base color is darker, the shadowing of the background is different, and the amount of blurring of the background under the popover is very different.
If I was setting the background of my popover content to a solid, non-alpha-transparent color, I wouldn't have any issues, but I am, and I cannot figure out how to access the view/layer which my content is being displayed in to change things.
Setting the backgroundColor of the UIPopoverPresentationController to something completely transparent (alpha = 0.0) doesn't give me a completely transparent popover. I implemented a UIPopoverPresentationControllerDelegate and tried to use the prepareForPopoverPresentation: method to access the view the popover content is inside of, and make modifications, but I can't seem to find it: superview() is nil, and the UIPopoverPresentationController.presentedView() is also nil (at least they are when that delegate method is called). The UIPopoverPresentationController.containerView() is not nil, and definitely is the overlay view in which the popover is displayed...but that isn't the view I'm looking for.
So...I'm wondering what I'm missing here. I would very much prefer not to have to implement my own UIPopoverBackgroundView as the popoverBackgroundViewClass though I know that is a possibility.

Set navigationbar size according to background image

I have set an backgroundImage for my navigationbar. This works fine. But I would like to have the navigationbar height to be adjusted to the background image. At the moment the width of the background images is also not set according to the screen size.
I tried setting the height of the navigationbar like described here. This shows a bigger navigationbar for like a second but then it shrinks to its default size again.
Does anyone know how to achieve what I want? Here is an example of what I want to achieve: image
Apple Documentation:
It is permissible to customize the appearance of the navigation bar
using the methods and properties of the UINavigationBar class but you
must never change its frame, bounds, or alpha values or modify its
view hierarchy directly.
To achieve the effect seen in the image you tagged, they are most likely using a collection view to layout their data and that image is part of the collection view's header. They made the navigation bar background color clear, but the image is definitely not part of the navigation bar itself.
Apple recommends to never change the frame of a navigation bar manually because it messes with the layout code of its subviews and animation methods.
You could either subclass the navigation bar and attempt to create something similar, or go the easier route and make the navigation bar clear (UIColor(white: 0, alpha: 1) not .clear otherwise it might show up incorrectly) and have an underlying view display the image (e.x. a collection view whos header extends to the top of the view controller).
This will allow you to adjust the image height and width freely without subclassing the navigation bar, and creating potential bugs.
You can make custom NavigationBar class.
It can be help you
https://developer.apple.com/library/archive/samplecode/NavBar/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007418-Intro-DontLinkElementID_2

Whiteline issues while popping from view controller

My case navigation bar color different for two controllers. When I pop from a second view controller to first one there is white line glitch in UI appears. I don't understand why issues happen, is set navigation bar shadow image to nil and use a background image for setting navigation bar background.
one reason that can cause this, is extra content from other screens overlapping each other..
try to set each view controller to have
clipsToBounds = true
See Description from Apple...
Setting this value to true causes subviews to be clipped to the bounds
of the receiver. If set to false, subviews whose frames extend beyond
the visible bounds of the receiver are not clipped. The default value
is false.
another cause is, some view controller has a background with clear color...
make sure each view controller has a non clear background.
EDIT
the question was not clear enough, it looks like I didn't understand well, try to change the tint color of navigation bar to clear.
Finally, I found my issues, issues are when I am setting a navigation bar from orange to white I set the translucent property of the navigation bar is true. which cause the problem for me to display a white line.

Why can't I set the navigation controller background color in the storyboard?

I don't understand why the background color setting in the storyboard doesn't work for my navigation controller? (See picture)
http://ctrlv.in/299323
I have here set it to bright red but as you can see it does nothing in the storyboard or to the app when I build it.
Any thoughts?
I know I can set the color programmatically, and this is what I am currently doing. However, it would be nice to see the changes in the storyboard so I don't have to build the app every time I make a color change to see the difference.
Yes you can. Notice that you're changing UIView properties not Navigation bar. Look at the screen below:
You have to set Bar Tint property.

Disable the shadow on UIPopoverViewController's content view

I'm creating a custom popover for a UIPopoverController by subclassing UIViewController to manage the content view and UIPopoverBackgroundView for a custom background. Everything works great, except the UIPopoverController is applying a shadow to the content view, making the content appear bordered with shadow. I can't seem to find which view's layer is shadowed. How can I disable this shadow? Has anyone else ran into this problem?
As this is still standing months later, I'll close this by saying I implemented my own popup controller. It's a shame, though, one would think there would be a better way...

Resources