我想使自己的Navigationbar变色。所以我在ViewDidLoad中尝试了这样

self.navigationController.navigationBar.hidden=NO;

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage=[UIImage new];

self.navigationController.navigationBar.translucent=YES;

self.navigationController.navigationBar.topItem.titleView.tintColor=[UIColor blackColor];
self.navigationController.navigationBar.topItem.title=[lan GetConvertedLanguageString:@"My Profile"];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];



self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"backarrow"] style:UIBarButtonItemStylePlain target:self action:@selector(revealToggle :)];
[self.navigationController navigationBar].tintColor = [UIColor whiteColor];

但是在我的视图控制器中什么都看不到。此代码有什么问题?请帮我。
谢谢

最佳答案

屏幕截图


[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage=[UIImage new];
self.navigationItem.title = @"1234";
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Left" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
[self.navigationController navigationBar].tintColor = [UIColor whiteColor];

因此,我想您的“视图”背景为白色,因此您看不到白色文本。

注意

navigationBar.titleTextAttributes

显示栏标题文本的属性。

navigationBar.tintColor

应用于导航项目和条形按钮项目的颜色。

关于ios - 导航栏不出现,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34036492/

10-15 15:32