您的位置:首页 > 产品设计 > UI/UE

UI - NavigationController

2015-12-26 14:40 387 查看
/************************************* 导航栏的定制 *************************************/
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

//设置导航控制器:
//1.创建一个根视图控制器
ViewController *vc = [[ViewController alloc]init];
//2.vc作为导航控制器的根视图控制器
UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:vc];
//3.导航控制器是window的根视图控制器
self.window.rootViewController = navi;
navi.view.backgroundColor = [UIColor whiteColor];

/************************************* 导航控制器推出视图 *************************************/
SecondViewController *svc = [[SecondViewController alloc]init];

//    采用出栈入栈的方式推出下个页面 push pop 先进(栈底)后出(栈顶)
//1.进入下一个视图控制器
[self.navigationController pushViewController:svc animated:YES];
//2.返回上一个视图控制器
[self.navigationController popToRootViewControllerAnimated:YES];
//3.返回指定的视图控制器
[self.navigationController popToViewController:svc animated:YES];
//4.返回到根视图控制器
[self.navigationController popToRootViewControllerAnimated:YES];

//常用属性
//1.所有处于栈中的控制器
self.navigationController.viewControllers;
//2.位于栈顶的控制器
self.navigationController.topViewController;
//3.当前正在显示的控制器
self.navigationController.visibleViewController;
//4.导航条
self.navigationController.navigationBar;

/************************************* 导航控制器的创建 *************************************/

//    一、对导航栏的定制: 影响每个子视图
//    self.navigationController.navigationBar
//(1)半透明效果(默认打开, 若关闭, 左边原点会在导航栏的左下方, 整个屏幕下移)
self.navigationController.navigationBar.translucent = YES;
//调整: 状态栏20 导航栏44(横屏 32)

//(2)背景颜色(最上层导航栏)
self.navigationController.navigationBar.barTintColor = [UIColor yellowColor];
//(最下层导航栏)
self.navigationController.navigationBar.backgroundColor = [UIColor blackColor];

//(3)添加导航栏的背景图片, 半透明效果自动关闭
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"2.jpg"] forBarMetrics:UIBarMetricsDefault];

//    二、设置当前控制器显示在导航栏上的信息
//    self.navigationController.navigationItem
//(1)设置标题
//1.第一种方式:推荐
self.navigationItem.title = @"第一页";
//2.第二种方式: 会影响其他的东西
//    self.title = @"首页";
//(2)自定义标题视图
self.navigationItem.titleView = [[UISegmentedControl alloc]initWithItems:@[@"消息", @"电话"]];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(leftBarButtonAction:)];

//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"变色" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonAction:)];

//使用矢量图: 百度阿里巴巴矢量图
//    imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal(取消渲染)
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"4.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonAction:)];
//渲染颜色设置
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: