对于父级VC与子级VC分别有navigationController的情况,即不是使用push方式加载子VC,而是通过AddChildViewController的方式添加的场景,则父级导航条会覆盖在子级导航条上面,所以需要在载入时把父级导航条做隐藏处理:
在含有导航条的ViewController中,VC的navigationItem与VC.navigationController中的 navigationItem并不是同一个对象,如下图所示。
[self.flagshipStoreTabBarItem setTitle: @"发现"];
// [self.flagshipStoreTabBarItem setImage: [UIImage imageNamed: @"FhipedIcon"]];
[self.flagshipStoreTabBarItem setFinishedSelectedImage: [UIImage imageNamed: @"FhipedIcon"] withFinishedUnselectedImage: [UIImage imageNamed: @"FhipIcon"]];
UINavigationController view层级
http://sinye.iteye.com/blog/2093281
(Good)【IOS开发】UITabBarController和UINavigationController结合使用。
http://blog.sina.com.cn/s/blog_721cd3390101vr2d.html
titleView要在具体ViewController中实现,而不是在NavigationViewController中实现。后者显示不出来。
UIBarButtonItem * backItem = [[UIBarButtonItem alloc] initWithImage: [UIImage imageNamed: @"BackNavIcon"] style: UIBarButtonItemStylePlain target: self action: @selector(backTo)];
[backItem setTitle:@"Test"];
[self.navigationItem setLeftBarButtonItem: backItem];
错误做法:
UIBarButtonItem * backItem = [[UIBarButtonItem alloc] init];//BackNavIcon
[backItem setTitle: @"Test"];
[backItem setImage: [UIImage imageNamed: @"ForeIcon"]];
[self.navigationItem setBackBarButtonItem: backItem];
【iOS开发-22】navigationBar导航条和navigationItem设置:基本搞定导航条上的文字和按钮以及各种跳转
http://www.tuicool.com/articles/BZNVza
Creating a left-arrow button (like UINavigationBar's “back”style) on a UIToolbar
HJAddVC * addVC = [[HJAddVC alloc] init];
UINavigationController * addNavController = [[UINavigationController alloc] initWithRootViewController: addVC];
[addNavController addChildViewController: addVC];
[rootVC.view addSubview: addNavController.view];
[rootVC addChildViewController: addNavController];
[addVC.view setFrame: rootVC.view.frame];
[addVC.view setBackgroundColor: [UIColor whiteColor]];
视图View与控制器都需要移除,缺一不可
- (void) closeView: (id)sender
{
[self.navigationController.view removeFromSuperview];
[self.navigationController removeFromParentViewController];
}
[self.navigationController.navigationItem setHidesBackButton: YES];
//透明导航栏
[self.navigationController.navigationBar setBackgroundImage: pressedColorImg forBarMetrics: UIBarMetricsDefault];
IOS开发---菜鸟学习之路--(二十四)-iOS7View被导航栏遮挡问题的解决
http://www.cnblogs.com/PleaseInputEnglish/p/3498032.html
将NavigationBar设置透明(仅将指定视图控制器进行透明处理),步骤如下:
1.在视图控制器的头文件中实现UINavigationControllerDelegate,例如:
@interface PicturePreviewViewController: UIViewController
2.在实现类中加入这个代理的方法及具体操作如下:
- (void) navigationController: (UINavigationController *)navigationController willShowViewController: (UIViewController*) viewController animated: (BOOL)animated{
//如果进入的是当前视图控制器
if (viewController == self) {
//背景设置为黑色
self.navigationController.navigationBar.tintColor= [UIColor colorWithRed:0.000 green:0.000 blue:0.000 alpha:1.000];
//透明度设置为0.3
self.navigationController.navigationBar.alpha= 0.300;
//设置为半透明
self.navigationController.navigationBar.translucent = YES;
} else {
//进入其他视图控制器
self.navigationController.navigationBar.alpha = 1;
//背景颜色设置为系统默认颜色
self.navigationController.navigationBar.tintColor = nil;
self.navigationController.navigationBar.translucent = NO;
}
}
navigationBar translucent
http://blog.csdn.net/yongyinmg/article/details/39957741
最近iOS项目中要求导航栏的返回按钮只保留那个箭头,去掉后边的文字,在网上查了一些资料,最简单且没有副作用的方法就是:
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment: UIOffsetMake(0, -60)
forBarMetrics: UIBarMetricsDefault];
参考自这里:http://stackoverflow.com/questions/19078995/removing-the-title-text-of-an-ios-7-uibarbuttonitem
[self.navigationItem setHidesBackButton: YES];
方法一:(自定义视图的方法,一般人也会采用这样的方式)
就是在导航向上添加一个titleView,可以使用一个label,再设置label的背景颜色透明,字体什么的设置就很简单了。
//自定义标题视图
UILabel *titleLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, 200, 44)];
titleLabel.backgroundColor = [UIColor grayColor];
titleLabel.font = [UIFont boldSystemFontOfSize: 20];
titleLabel.textColor = [UIColor greenColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = @"新闻";
self.navigationItem.titleView = titleLabel;
方法二:(在默认显示的标题中直接修改文件的大小和颜色也是可以的)
[self.navigationController.navigationBar setTitleTextAttributes: @{NSFontAttributeName: [UIFont systemFontOfSize: 19], NSForegroundColorAttributeName: [UIColor redColor]}];
方式二相对于方式一而言更加简单方便
//声明这张图片用原图(别渲染),默认有亮蓝色渲染
UIImage *img = [UIImage imageNamed: @"ShareIcon"];
img = [img imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
_shareItem = [[UIBarButtonItem alloc] initWithImage: img style:UIBarButtonItemStylePlain target: self action: @selector(shareTo)];
TabBar与导航条混用时,TabBarItem的设置是在NavigationController中,而不是内容Controller中,切记!!!否则会导致页面切换时选中状态不准确。
Tabbar的隐藏函数,其实只在Nav Push的之前调用时起作用
//隐藏Tabbar
[viewController setHidesBottomBarWhenPushed: YES];
[super pushViewController: viewController animated: animated];
而Tabbar的显示,则只有在Pop函数调用前执行才真正起作用
//显示Tabbar
if ([viewController isKindOfClass: [RootVC class]]) {
[viewController setHidesBottomBarWhenPushed: NO];
}
return [super popToViewController: viewController animated: animated];
自定义iOS 7 导航栏背景,标题和返回按钮文字颜色
http://blog.csdn.net/mad1989/article/details/41516743
IOS自定义导航栏题目和返回按钮标题
http://blog.csdn.net/hengshujiyi/article/details/29864339
UINavigationBar自定义返回按钮的设置
http://blog.sina.com.cn/s/blog_bf9843bf0101g01b.html
uibarbuttonitem image蓝色
http://www.cocoachina.com/bbs/read.php?tid-180226-page-1.html
(good)iOS 7 UITabBar自定义选中图片显示为默认蓝色的Bug