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];
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;
导航状态栏(UINavigationBar)和分栏状态栏(UITabBar)
原文地址:http://blog.csdn.net/loseway711/article/details/42127611