2

The code:

UIViewController *viewController = [[UIViewController alloc] initWithNibName:@"NibName" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
navigationController.navigationBar.tintColor = [UIColor redColor];
self.popoverController = [[[UIPopoverController alloc]     
initWithContentViewController:navigationController] autorelease];
popoverController.popoverContentSize = viewController.view.frame.size;
[popoverController presentPopoverFromRect:sender.frame inView:sender.superview
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[viewController release];
[navigationController release];

The tint color property of UINavigationBar doesn't work, it still has the default color. What could I be doing wrong?

Jasper
  • 2,166
  • 4
  • 30
  • 50
Alex Sfinx87
  • 244
  • 5
  • 16
  • In viewController: NSLog(@"Tint:%@", self.navigationController.navigationBar.tintColor); self.navigationController.navigationBar.tintColor = [UIColor brownColor]; NSLog(@"Tint:%@", self.navigationController.navigationBar.tintColor); Log: Tint:(null) Tint:UIDeviceRGBColorSpace 0.6 0.4 0.2 1 But visually tint color is not apllied. – Alex Sfinx87 Sep 08 '11 at 11:35
  • here I have another solution quite similar: http://stackoverflow.com/questions/8490261/change-color-navigation-controller-in-a-popover good luck!!! – TurboManolo Dec 14 '11 at 12:26

2 Answers2

5
self.popoverController.popoverBackgroundViewClass = [MyCustomBackgroundView class];

@interface MyCustomBackgroundView : UIPopoverBackgroundView {
@private
}
@end

@implementation MyCustomBackgroundView

@synthesize arrowOffset;
@synthesize arrowDirection;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor redColor];
    }
    return self;
}

+ (UIEdgeInsets)contentViewInsets {
    return UIEdgeInsetsMake(0, 0, 1, 0);
}

+ (CGFloat)arrowHeight{
    return 0.0;
}

+ (CGFloat)arrowBase{
    return 0.0;
}

@end
Alex Sfinx87
  • 244
  • 5
  • 16
3

As of iOS 5, popoverBackgroundViewClass is available which is the way to accomplish this.

akaru
  • 6,299
  • 9
  • 63
  • 102
  • 2
    Except the buttons that appear on the nav bar are still the blue-ish colour. Or at least they are for all the things I've tried. Have you managed to tint the buttons as well? – mattjgalloway Dec 07 '11 at 15:49
  • matt, to change the UIBarButtonItem's within the navigation controller you can do it using the iOS 5 `appearance` api. `[[UIBarButtonItem appearance] setTintColor:[UIColor blueColor]]` will change the color of your barButtonItem to be blue. [link](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html) – LightningStryk Jun 17 '13 at 22:07