2014-01-22 68 views
2

我的导航栏上有问题。 UIBarButtonItemtintColor是橙色的,但当我目前popover时,barButtonItemtintColor更改为lightGray。导航栏色调颜色是whiteColor。 popover后,我需要留下橙色。 有人可以帮我吗?谢谢!iOS 7 popover包含进度条和barbuttonItem色调颜色

EDIT 1

我使可选择barButtonItem和我的UIBarButtonItem的亚类:

-(void)setSelected:(BOOL)selected { 
    _selected = selected; 
    if (selected) { 
     self.tintColor = self.selectedColor; 
    } else { 
     self.tintColor = self.defaultColor; 
    } 
} 

-(id)initWithImage:(UIImage *)image style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action defaultColor:(UIColor *)defaultColor { 
    self = [super initWithImage:image style:style target:target action:action]; 
    if (self) { 
     self.tintColor = defaultColor; 
    } 
    return self; 
} 

-(id)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action defaultColor:(UIColor *)defaultColor { 
    self = [super initWithTitle:title style:style target:target action:action]; 
    if (self) { 
     self.tintColor = defaultColor; 
    } 
    return self; 
} 

编辑2

感谢名单沃伦伯顿为答案,解决方法是:

self.navigationController.navigationBar.tintAdjustmentMode = UIViewTintAdjustmentModeNormal; 

回答

4

此行为是iOS 7“正常”。它会告诉您的用户该按钮目前不是您活动用户界面的一部分。

如果你想绕过你也可以继承的UIBarButtonItem和覆盖此通常惯例

- (void)tintColorDidChange

只留下一个空的实现。

- (void)tintColorDidChange { 
    //nothing to see here, move along 
} 
当酥料饼呈现呈现视图

去tintMode UIViewTintAdjustmentModeDimmed所以,即使你提供了另一种颜色的颜色被变灰(去饱和?)由系统。

这就是为什么你需要重写tintColorDidChange来阻止这种情况。

从文档...

当此属性的值是UIViewTintAdjustmentModeDimmed的tintColor属性的 值被修改,以提供一个变暗 外观。

+0

我编辑了我的问题。我需要改变tintColor当我按下bar按钮,但当popover呈现 - 我需要防止颜色改变 –

+0

看到编辑 - 它解释 –

+0

谢谢,这可以帮助我! –

0

我已经改变栏按钮系统项目在外部编辑PNG文件的颜色,包括图像的项目,并通过

[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"UIButtonBarTrashBlack"] style:UIBarButtonItemStyleBordered target:self action:@selector(myAction)]; 

加载它解决了我的问题,我已经找到了内部系统映像使用有用的UIKit-Artwork-Extractor

我已经使用免费软件GIMP编辑了作品的颜色。

0

它确实看起来像一个苹果的错误,你应该输入一个错误与错误记者。这就是说,我可以给你一个相对简单的解决方法:此代码添加到您的RecipetTableViewController:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.title = @"Recipe Book"; 

    UIBarButtonItem *it = [[UIBarButtonItem alloc] initWithTitle:self.title style:UIBarButtonItemStylePlain target:nil action:NULL]; 
    UIImage * btBack_30 = [[UIImage imageNamed:@"btBack_30"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)]; 
    [it setBackButtonBackgroundImage:btBack_30 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 
    self.navigationItem.backBarButtonItem = it; 
} 

编辑:您可以DUP这个错误,如果有兴趣,更多的错误引用它就越有可能苹果会解决这个问题:

摘要:在第二次出现按钮之前,设置back bar按钮项目的UIBarButtonItem外观代理没有任何影响。

重现步骤:在的appDelegate,任何已经出现之前,添加以下语句:

UIImage * gradientImage44 = [[UIImage imageNamed:@"navBar_44"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
UIImage * gradientImage32 = [[UIImage imageNamed:@"navBar_32"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
// Set the background image for all UINavigationBars [[UINavigationBar appearance] setBackgroundImage:gradientImage44 forBarMetrics:UIBarMetricsDefault]; 
[[UINavigationBar appearance] setBackgroundImage:gradientImage32 forBarMetrics:UIBarMetricsLandscapePhone]; 

预期结果:当一个的viewController先推,它的后退按钮在它的形象。

实际结果:第一次出现时,没有图像。再次将视图推到那里。实际上,当你第一次点击按钮时,确实会出现,但当按钮第一次出现时不会出现。

版本:5.0.1的Xcode,iOS版7.0.3

注:在导航控制器的根视图控制器添加,这使得它的工作:

-(void)viewDidLoad 
{ 
[super viewDidLoad]; 

self.title = @"Recipe Book"; 
UIBarButtonItem *it = [[UIBarButtonItem alloc] initWithTitle:self.title style:UIBarButtonItemStylePlain target:nil action:NULL]; 
UIImage * btBack_30 = [[UIImage imageNamed:@"btBack_30"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)]; 
[it setBackButtonBackgroundImage:btBack_30 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; self.navigationItem.backBarButtonItem = it; 
} 

编码愉快!