0

I have a custom navigationBar that i create inside a viewController. Before iOS 11 what i did was:

-(void)prepareNavigationbar{
[navigationBar removeFromSuperview];

float version = [[[UIDevice currentDevice] systemVersion] floatValue];

if (version >= 7.0){
     navigationBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 64)];
}
else{
   navigationBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
}

navigationBar.tintColor = [UIColor blackColor];
navigationBar.barStyle = 1;



if ([navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
{
    if (version>=7.0){
        UIImage *gradientImage44 = [UIImage imageNamed:@"logostrip-568h"];
        [[UINavigationBar appearance] setBackgroundImage:gradientImage44
                                           forBarMetrics:UIBarMetricsDefault];
    }
    else{
        UIImage *gradientImage44 = [UIImage imageNamed:@"logo-strip"];
        [[UINavigationBar appearance] setBackgroundImage:gradientImage44
                                           forBarMetrics:UIBarMetricsDefault];
    }

}
else
{


    //NSLog(@"enter in to old version");
    [navigationBar drawRect:CGRectMake(0, 0, 320, 44)];
}


UINavigationItem *navigationItem    = [[UINavigationItem alloc] init];

[navigationBar pushNavigationItem:navigationItem animated:NO];
[self.view addSubview:navigationBar];
}

The code works just fine until iOS 11. Now the issue is that the custom background seems to be smaller then the navigationBar.

Note - I'm using xibs and i dont have any StoryBoard.

The issue in View Debuger

How can i fix it?

dudi hisine
  • 129
  • 11
  • 1
    You have to change `UINavigationBarContentView` frame height in `layoutSubviews` of `UINavigationBar`.. and constrain it. – Brandon Nov 26 '17 at 16:57
  • 1
    Thank you! I search what you told me to do and i found this: https://stackoverflow.com/a/46251867/7259763 And it works just fine. Thank you again for pointing me to the right direction – dudi hisine Nov 27 '17 at 13:08

0 Answers0