在iPhone 6/6 +上显示导航栏错误

时间:2015-07-05 23:51:41

标签: objective-c uinavigationcontroller uinavigationbar

我遇到了设置导航栏的问题。

我有一个嵌入导航控制器的UIViewController。

在视图中我写了加载:

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"tab_nav_white.png"] forBarMetrics: UIBarMetricsDefault];

但它在右侧和左侧显示错误。它发生在iPhone 6/6 +上,适用于iPhone 4,5。你知道原因吗?谢谢!

enter image description here

如果我使用init方法定制uinavigationcontroller,它会很好地显示。我不明白为什么:

  
      
  • (id)initWithRootViewController:(UIViewController *)rootViewController background:(UIImage *)background font:(UIFont *)font {
  •   
if (self = [super initWithRootViewController:rootViewController]) {

    if([self.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {

        NSShadow *shadow = [NSShadow new];
        [shadow setShadowColor: [UIColor clearColor]];
        [shadow setShadowOffset: CGSizeMake(1, -1.0f)];


        if (SYSTEM_VERSION <7) {

            settings = @{
                         UITextAttributeFont                 :  font,
                         UITextAttributeTextColor            :  [UIColor whiteColor],
                         UITextAttributeTextShadowColor      :  [UIColor clearColor],
                         UITextAttributeTextShadowOffset     :  [NSValue valueWithUIOffset:UIOffsetMake(1,-1)],
                         };
        }
        else{

            settings = @{
                         NSFontAttributeName                 :  font,
                         NSForegroundColorAttributeName      :  [UIColor whiteColor],
                         NSShadowAttributeName               :  shadow,
                         };
        }

        [[UINavigationBar appearance] setTitleTextAttributes:settings];
        [self.navigationBar setTitleVerticalPositionAdjustment:2.0f forBarMetrics:UIBarMetricsDefault];
        [self.navigationBar setBarStyle:UIBarStyleDefault];

    }
}
return self;

}

0 个答案:

没有答案