我有一个我在viewController中创建的自定义navigationBar。 在iOS 11之前我做的是:
-(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];
}
代码工作正常,直到iOS 11。 现在的问题是自定义背景似乎比navigationBar小。
注意 - 我正在使用xibs,而且我没有任何StoryBoard。
我该如何解决?