把子控制器添加到导航控制器中
(1)
YYOneViewController *one=[[YYOneViewController alloc]init];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:one];
(2)
UINavigationController *nav=[[UINavigationControlleralloc]init];
self.window.rootViewController=nav;
YYOneViewController *one = [[YYOneViewController alloc] init];
[nav addChildViewController:one];
(3)
YYOneViewController *one = [[YYOneViewController alloc] init];
[email protected][one];(添加到导航控制器的栈中)
当前子控制器界面导航栏的标题以及对应返回标题的设置
[email protected]"第一个界面";
self.navigationItem.backBarButtonItem=[[UIBarButtonItemalloc]initWithTitle:@"返回一"style:UIBarButtonItemStylePlain target:nilaction:nil];
给导航栏添加按钮
self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:nil action:nil];
界面跳转
跳转到第二个界面(当前为第三个,移除当前栈顶的控制器) [self.navigationControllerpopViewControllerAnimated:YES];
移除处理栈底控制器之外的所有控制器 [self.navigationControllerpopToRootViewControllerAnimated:YES];
只要传入栈中的某一个控制器,就会跳转到指定控制器 [self.navigationController popToViewController:viewcontroller animated:animated];
iOS7之后 要想改变navigationbar的颜色 可以这样子改
self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#3A3A3A" alpha:1.0f];
默认带有一定透明效果,可以使用以下方法去除系统效果
[self.navigationController.navigationBar setTranslucent:NO];
给navigationBar设置图片
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"32050"] forBarMetrics:UIBarMetricsDefault];
改变UINavigationBar导航条标题颜色和字体
[self.navigationController.navigationBar setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:0 green:0.7 blue:0.8 alpha:1], NSForegroundColorAttributeName,
[UIColor colorWithRed:0 green:0.7 blue:0.8 alpha:1],NSShadowAttributeName,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], NSShadowAttributeName,
[UIFont fontWithName:@"Arial-Bold" size:0.0], NSFontAttributeName,
nil]
];
改变状态栏的颜色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[viewController setNeedsStatusBarAppearanceUpdate];如果没效果,
可在plist文件里设置View controller-based status bar appearance = NO
设置为:View Controller 不对status Bar 显示进行操作
在某些页面控制navigationbar不显示
[self.navigationController setNavigationBarHidden:YES animated:animated];
如果整条导航填颜色是通过颜色色值来加载的话,这时候系统相册调用出来的颜色就是系统默认的,导致白色导航条,白色文字就会显示不出来,从而影响用户体验;还有一种情况是,调用系统相册之后,导航条上的文字,和取消按钮都是显示的英文,跟我们整体风格格格不入,因此我们需要重写相册导航条上的内容、图片和文字以及文字颜色.
// 实现navigationController的代理
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
viewController.navigationController.navigationBar.barTintColor = MainAppColor;
[viewController.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica Neue" size:19.0f], NSFontAttributeName,nil]];
viewController.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
}
在调用系统相册、相机发现是英文的系统相簿界面后标题显示“photos”,但是手机语言已经设置显示中文,在info.plist设置解决问题 info.plist里面添加Localized resources can be mixed YES 表示是否允许应用程序获取框架库内语言。
获取view上所有的层级结构
- (NSString *)digView:(UIView *)view { if ([view isKindOfClass:[UITableViewCell class]]) return @""; // 1.初始化 NSMutableString *xml = [NSMutableString string]; // 2.标签开头 [xml appendFormat:@"<%@ frame=\"%@\"", view.class, NSStringFromCGRect(view.frame)]; if (!CGPointEqualToPoint(view.bounds.origin, CGPointZero)) { [xml appendFormat:@" bounds=\"%@\"", NSStringFromCGRect(view.bounds)]; } if ([view isKindOfClass:[UIScrollView class]]) { UIScrollView *scroll = (UIScrollView *)view; if (!UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, scroll.contentInset)) { [xml appendFormat:@" contentInset=\"%@\"", NSStringFromUIEdgeInsets(scroll.contentInset)]; } } // 3.判断是否要结束 if (view.subviews.count == 0) { [xml appendString:@" />"]; return xml; } else { [xml appendString:@">"]; } // 4.遍历所有的子控件 for (UIView *child in view.subviews) { NSString *childXml = [self digView:child]; [xml appendString:childXml]; } // 5.标签结尾 [xml appendFormat:@"</%@>", view.class]; return [xml copy]; }