Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize / style a UIPopoverController

I'm working on an iPad application and I'm using UIPopoverControllers. I'm at the part where the app needs to be branded and styled and i'm wondering how to change the color / tint of the UIPopoverController? Standard is dark blue but it needs to be another color..

is this possible?

Greets, Thomas

like image 888
Thomas Joos Avatar asked Mar 31 '10 12:03

Thomas Joos


4 Answers

This is possible starting in iOS 5.0 by subclassing the abstract class UIPopoverBackgroundView and assigning your subclass to the popoverBackgroundViewClass property on your UIPopoverController instance. Unfortunately there is no tintColor property as the popover needs to use images for it's arrow and border in order to achieve smooth animations during dynamic resizing. You can learn more about how to customize the appearance of a UIPopoverController in the UIPopoverBackgroundView Class Reference

like image 59
Andrew Avatar answered Nov 18 '22 01:11

Andrew


It's impossible for now.

It's what I call the "Box in a Box" model. You get control of the box inside of the box (the UIViewController inside of the UIPopoverController), but you have very limited control over the actual popover itself. Outside of the arrow direction and the size, you can't change much else. There are also options for a modal effect popover, which dims everything else when it shows up, but I haven't tried to get it working.

I'm sure you've noticed there is no UIPopover class by now.

The answer you want to hear:
If you really want to style one that bad, just write your own. It's really not that hard.

The link you want to click:
Cocoacontrols is an index of iOS and OSX components available on GitHub, they have some popover stuff.

like image 21
Sneakyness Avatar answered Nov 18 '22 03:11

Sneakyness


iOS 7 introduces backgroundColor property of UIPopoverController which affects/includes the navigation background color as well as arrows of popover.

@property (nonatomic, copy) UIColor *backgroundColor NS_AVAILABLE_IOS(7_0);

Usage example:

    if ([self.popoverVC respondsToSelector:@selector(setBackgroundColor:)]) {   // Check to avoid app crash prior to iOS 7
        self.popoverVC.backgroundColor = [UIColor greenColor];   // [UIColor colorWithPatternImage:@"..."] doesn't reflect the color on simulator but on device it works!
    }

Note - As of now (iOS 7.0.3), in some cases (like set color using colorWithPatternImage:), the simulator (and even some devices) doesn't honor the color.

like image 13
Ashok Avatar answered Nov 18 '22 02:11

Ashok


Throwing my hat in here;

I've leveraged UIPopoverBackgroundViews in iOS 5+ to add a simple tintColor property onto UIPopoverControllers.

PCPopoverController: https://github.com/pcperini/PCPopoverController

like image 8
Patrick Perini Avatar answered Nov 18 '22 03:11

Patrick Perini