2

With iOS 11 navigation bar's title view and bar button item is not centered. Also the background image's height does not change and is not shown in full.The bar height is 74.

enter image description here See the white space.

I have tried this

if(@available(iOS 11,*)){
    _homeNavigationBar.prefersLargeTitles = NO;
    _homeNavigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeNever;
    [_homeNavigationBar setBarTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"navbarBg.png"]]];
}
else{
    [_homeNavigationBar setBackgroundImage:[UIImage imageNamed:@"navbarBg.png"] forBarMetrics:UIBarMetricsDefault];
}

But still i am unable to center the title and bar button item.

Any idea how can i fix this?Please do let me know.Thanks

iYousafzai
  • 1,021
  • 1
  • 10
  • 29

1 Answers1

0

Subclassing the navigation bar did the trick for me.

- (void)layoutSubviews {
[super layoutSubviews];

for (UIView *view in self.subviews) {
    if([NSStringFromClass([view class]) containsString:@"Background"]) {
        view.frame = self.bounds;
    }
    else if ([NSStringFromClass([view class]) containsString:@"ContentView"]) {
        CGRect frame = view.frame;
        frame.origin.y = 25;
        view.frame = frame;
    }
 }
}
iYousafzai
  • 1,021
  • 1
  • 10
  • 29
  • This is **incorrect**. The status bar was _sometimes_ 20 high in previous iOS versions. (could also be 40). You should never assume a fixed height. – Ashley Mills Oct 03 '17 at 08:05