我想创建一个没有彩色背景的UINavigationBar
。
我试过了
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
和
self.navigationController.navigationBar.backgroundColor = nil;
但无法解决问题。我还尝试为导航栏设置与
self.view.backgroundColor
相同的颜色,但无法覆盖原始颜色。 (我正在使用Storyboard,这可能会导致问题,但不确定,因为我可以使用代码操纵tintColor
。) 最佳答案
self.navigationController.navigationBarHidden = NO;
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
//[backButton setImage:[UIImage imageNamed:@"you_back_image"] forState:UIControlStateNormal]; this is the image you would use as a back image
[backButton setTitle:@"back" forState:UIControlStateNormal];
[backButton sizeToFit];
[backButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* backBarButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = backBarButton;
然后编写方法
goBack
,这取决于您是否展示或推送了当前的ViewController。- (void)goBack {
//[self dismissViewControllerAnimated:YES]
//[self.navigationController popViewControllerAnimated:YES];
}
关于ios - 没有backgroundColor的UINavigationBar,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28035817/