2

代碼:色調顏色不起作用

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]; 

UINavigationBar着色顏色屬性不起作用,它仍然有默認的顏色。 我能做什麼錯?

+0

在的viewController: 的NSLog(@ 「色調:%@」,self.navigationController.navigationBar.tintColor); self.navigationController.navigationBar.tintColor = [UIColor brownColor]; NSLog(@「Tint:%@」,self.navigationController.navigationBar.tintColor); 日誌: 色調:(null) 色調:UIDeviceRGBColorSpace 0.6 0.4 0.2 1 但視覺上的淺色不平衡。 –

+0

這裏我有另一種解決方案很相似:http://stackoverflow.com/questions/8490261/change-color-navigation-controller-in-a-popover祝你好運! – TurboManolo

回答

3

從iOS 5開始,可以使用popoverBackgroundViewClass來實現這一點。

+2

除導航欄上顯示的按鈕仍爲藍色。或者至少他們是爲了我嘗試過的所有事情。你是否設法給按鈕着色? – mattjgalloway

+0

matt,要更改導航控制器內的UIBarButtonItem,可以使用iOS 5'appearance' api來完成。 '[[UIBarButtonItem appearance] setTintColor:[UIColor blueColor]]'會改變barButtonItem的顏色爲藍色。 [鏈接](http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html) – LightningStryk

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