UINavigationcontroller

---恢复内容开始---

UINavigationcontroller:导航控制器,用于父子页面的转换。一般用堆栈的方式管理UIViewController,用户可以从上一界面进入下一届面,在下一届面简单的回到上一届面。这里再简单介绍一下堆栈。

堆栈:堆栈是一种执行“后进先出”算法的数据结构。它是在内存中开辟一个存储区域,数据一个一个顺序的存入(也就是“压入-push”),开始存入的数据叫做“栈底”,读取这些数据的过程叫做“弹出POP”,这样就实现了后进先出的原则。

实现:

appdelegate中:

ViewController *vc = [ViewController alloc]init];
UINavigationcontroller *nav = [UINavigationtroller alloc]initWithRootViewController:vc];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];

 

ViewController:

self.title = @"导航控制器";
self.navigationController.navigationBar.titleTextAttribuets = [NAMutableDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSFore]//导航条标题的颜色
self.navigationController.navigationBar.barTintColor = [UIColor redColor];//导航条的背景颜色
//[self.navigationController.navigationBar setBarTintColor:[UIColor purple]]同上
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""]forBarMertrics:UIBarMertricsDefault]];//设置背景图片
self.navigationController.translucent = NO;//导航条半透明状态,默认为yes
self.navigationController.navigationBarHidden = YES;//隐藏导航条
[self.navigationController setNavigationBarHidden:YES animated:YES];//隐藏导航条,是否带动画
UIBarButtonItem *backButton = [UIBarButtonItem alloc]initWithTitle:@"返回"style:UIBarButtonItemStylePlain target:self action:nil];//设置导航条的返回按钮的标题
self.navigationItem.backBarButtonItem = backButton;

--------自定义返回按钮-------(写在哪个界面,在哪个界面有效果)
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.fram = CGRectMake(10,10,40,40);
[button setTitle:@"返回"forState:UIControlStateNormal];
[button setTitleColor:[UIColor white]forState:UIControlStateNormal];
UIBarButtonItem *left = [[UIBarButtonItem alloc]initWithCustomView:button];
self.navigationItem.leftBarButtonItem = left;

----------自定义titleView------------------------
UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:@[@"1",@"2"]];
seg.fram = CGRectMake(0,10,80,20);
self.navigationItem.titleView  = seg;

 

 

posted on 2016-07-08 10:56  人家小姐  阅读(148)  评论(0)    收藏  举报

导航