//*************导航状态栏(UINavigationController)***************
1.在导航控制器中,所有的子视图控制器共用一个导航状态栏
UINavigationBar *navBar = self.navigationController.navigationBar
2.可设置导航栏的显示风格
navBar.barStyle = UIBarStyleDefault;
3.可设置导航栏的不透明度,默认为YES(不透明)
//如果设置为透明,则子视图的左上角坐标原点为从(0,0)开始
//如果设置为不透明,则子视图的左上角坐标原点为从(0,20+44)开始
//导航栏高度:44,顶部状态栏高度:20
navBar.translucent = NO; (透明)
4. 可设置导航栏的背景颜色
navBar.barTintColor = [UIColor redColor];
5.可设置导航栏的背景图片
//竖屏模式:UIBarMetricsDefault
//横屏模式:UIBarMetricsCompact
[navBar setBackgroudImage:[UIImage ImageNamed:@“XXX.jpg”] forBarMetrics:UIBarMetricsDefault];
//*************导航元素项(UINavigationItem)***************
1.导航元素项(navigationItem)属于子视图控制器,即每个子视图控制器都有自己的导航元素项
self.navigationItem.title = @“视图一”; (设置导航栏标题方式一:通过文字)
UIView *view = [UIView alloc]initWithFrame:CGRectMake(0,0,30,30);
view.background = [UIColor redColor];
self.navigationItem.titleView = view; (设置导航标题方式二:通过视图,优先级最高)
2.下一个视图控制器的返回按钮是由上一个视图控制器来创建的,返回按钮如果没有创建,系统会自动创建,并且将当前控制器的标题设为返回按钮的标题,这个返回按钮是给下一个视图控制器使用,如果返回按钮的问题太长,不能完全显示,则自动替换为Back
self.navigationItem.backBarButtonItem = [UIBarButtonItem alloc]initWithTitle:@“帮助1” style:UIBarButtonStylePlain target
:nil action:nil];
2.1设置当前导航元素项的左元素项
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@“帮助2" style:UIBarButtonItemStylePlain target:nil action:nil];
2.2创建导航元素项按钮(标题方式),并设置为当前视图的右元素项
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithTitle:@"编辑" style:UIBarButtonItemStyleDone target:self action:@selector(rightClick)];
self.navitaionItem.rightBarButtionItem = rightItem;
2.3创建系统样式的按钮
UIBarButtonItem *rightItem2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:nil];
self.navigationItem.rightBarButtonItem = rightItem2;
2.4创建自定义样式按钮
UIView *view2 = [[UIView alloc]init];
view2.frame = CGRectMake(0, 0, 30, 30);
view2.backgroundColor =[UIColor redColor];
UIBarButtonItem *rightItem3 = [[UIBarButtonItem alloc]initWithCustomView:view2];
self.navigationItem.rightBarButtonItem = rightItem3;
2.5创建图片样式按钮
UIImage *image = [UIImage imageNamed:@"user_total"];
//强制设置图像为原始的描画方式显示
UIImage *image1 = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *rightItem4 = [[UIBarButtonItem alloc]initWithImage:image1 style:UIBarButtonItemStyleDone target:nil action:nil];
self.navigationItem.rightBarButtonItem = rightItem4;
//设置左元素项数组,并且会覆盖掉原有元素项
self.navigationItem.leftBarButtonItems = @[rightItem2,rightItem3,rightItem4];
//设置右元素项数组,并且会覆盖原有元素项
self.navigationItem.rightBarButtonItems = @[rightItem2,rightItem3,rightItem4];
//*****************分栏状态栏(UITabBarController)****************
1.分栏控制器的分栏状态栏属于分栏控制器,但分栏按钮是属于子视图控制器
UITabBar *tabBar = tabBarCtrl.tabBar; (获取分栏控制器的分栏)
2.可设置分栏的透明度
tabBar.translucent = NO;
3.可设置分栏的显示风格
tabBar.barStyle = UIBarStyleBlack;
4.可设置选中按钮的标题的颜色
tabBar.tintColor = [UIColor redColor];
5.可设置分栏的前景颜色
tabBar.barTintColor = [UIColor blueColor];
6.可设置分栏是否隐藏
tabBar.hidden = NO;
7.可设置分栏的背景图片
tabBar.backgroundImage = [UIImage ImageNamed:@“XXX.jpg”];
//********************分栏元素项(UITabBarItem)*********************
1.创建分栏元素项的方式1:系统自动创建
FirstViewController *firstVC = [[FirstViewController alloc]init];
firstVC.title = @"视图一";
//tabBarItem为系统自动创建 lazily方法
firstVC.tabBarItem.title = @"VC1";
SecondViewController *secondVC = [[SecondViewController alloc]init];
2.创建分栏元素项的方式2:创建系统类型的按钮
//参数1:系统风格类型
//参数2:按钮的tag值
UITabBarItem *item2 = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];
secondVC.tabBarItem = item2;
secondVC.title = @"VC2";
ThirdViewController *thirdVC = [[ThirdViewController alloc]init];
3.创建分栏元素项的方式3:创建标题和图片样式的按钮
UITabBarItem *item3 = [[UITabBarItem alloc]initWithTitle:@"视图三" image:[UIImage imageNamed:@"tab_0"] tag:0];
thirdVC.tabBarItem = item3;
FouthViewController *fouthVC = [[FouthViewController alloc]init];
4.创建分栏元素项的方式4:
//按照图片原始方式绘制效果
UIImage *image = [UIImage imageNamed:@"tab_friend_select"];
UIImage *image1 = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UITabBarItem *item4 = [[UITabBarItem alloc]initWithTitle:@"视图四" image:[UIImage imageNamed:@"tab_friend_normal"] selectedImage:image1];
fouthVC.tabBarItem = item4;