代码:
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 :(得分: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
答案 1 :(得分:3)
从iOS 5开始,uipopoverBackgroundView类可用,这是实现此目的的方法。