【问题标题】:Tint color of UINavigationBar in UIPopoverController doesn't workUIPopoverController 中 UINavigationBar 的色调颜色不起作用
【发布时间】:2011-09-08 10:38:54
【问题描述】:

代码:

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 的 tint color 属性不起作用,它仍然具有默认颜色。 我可能做错了什么?

【问题讨论】:

  • 在viewController中:NSLog(@"Tint:%@", self.navigationController.navigationBar.tintColor); self.navigationController.navigationBar.tintColor = [UIColor brownColor]; NSLog(@"Tint:%@", self.navigationController.navigationBar.tintColor);日志:Tint:(null) Tint:UIDeviceRGBColorSpace 0.6 0.4 0.2 1 但未应用视觉上的色调。
  • 这里我有另一个非常相似的解决方案:stackoverflow.com/questions/8490261/…good luck!!!

标签: ios uinavigationcontroller uinavigationbar uipopovercontroller tintcolor


【解决方案1】:
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

【讨论】:

    【解决方案2】:

    从 iOS 5 开始,popoverBackgroundViewClass 可用,这是实现此目的的方法。

    【讨论】:

    • 除了出现在导航栏上的按钮仍然是蓝色的。或者至少它们适用于我尝试过的所有事情。你也设法给按钮上色了吗?
    • matt,要更改导航控制器中的 UIBarButtonItem,您可以使用 iOS 5 appearance api 来完成。 [[UIBarButtonItem appearance] setTintColor:[UIColor blueColor]] 会将 barButtonItem 的颜色更改为蓝色。 link
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 2013-11-14
    • 2013-01-12
    相关资源
    最近更新 更多