设置NavigationBar和UITabBarItem的属性

一:NavigationBar

1 、设置导航栏颜色

self.navigationController.navigationBar.barTintColor= [UIColor whiteColor];

2、设置导航栏子视图的颜色(例如返回按钮颜色)

self.navigationController.navigationBar.tintColor=[UIColor whiteColor];

3、设置导航栏背景图片

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBar"]forBarMetrics:0];

4、取消导航栏最下面的线条(必须设置背景图片才能取消)

self.navigationController.navigationBar.shadowImage= [[UIImage alloc]init];self.navigationController.navigationBar.translucent=NO;

5、ScrollView是否可以滚动至导航栏或TabBar下面,默认为YES

self.automaticallyAdjustsScrollViewInsets=NO;

6、导航栏字体大小和颜色

[self.navigationController.navigationBar setTitleTextAttributes:

@{NSFontAttributeName:[UIFont systemFontOfSize:19],

NSForegroundColorAttributeName:[UIColor whiteColor]}];

7、添加多个栏按钮项目:

UIBarButtonItem *shareItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(clickPopoverButton:)];

UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(clickPopoverButton:)];

self.navigationItem.rightBarButtonItems = @[shareItem,cameraItem];  //从右往左

8、使用图片作为导航栏标题。设置了 titleView 后,标题自动会隐藏:

self.title=@"popover";

self.navigationItem.titleView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"qrcode_screen"]];

9、设置左边按钮和back按钮同时存在:

//在push进去的控制器里设置

self.navigationItem.leftItemsSupplementBackButton = YES;

10.设置导航栏不透明

self.navigationController.navigationBar.translucent = NO;

二:UITabBarItem

1.改变UITabBarItem 字体颜色

[[UITabBarItem appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColorwhiteColor],UITextAttributeTextColor,nil]forState:UIControlStateNormal];

[[UITabBarItemappearance]setTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorcolorWithHexString:"#00C8D3"],UITextAttributeTextColor,nil]forState:UIControlStateSelected];

2.改变UITabBarItem 字体颜色和大小

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"Helvetica" size:12.0f],NSFontAttributeName,nil] forState:UIControlStateNormal];

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"Helvetica" size:12.0f],NSFontAttributeName,nil] forState:UIControlStateSelected];

3.改变UITabBarItem的选中和非选中图片

nav1.tabBarItem.image = [ImageNamed(@"tabicon1_unselect") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

nav1.tabBarItem.selectedImage = [ImageNamed(@"tabicon1_select") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

4.改变UITabBarController的颜色

UIView*mView=[[UIViewalloc]initWithFrame:CGRectMake(0,0,320,48)];//这是整个tabbar的颜色

[mViewsetBackgroundColor:[UIColorcolorWithPatternImage:[UIImageimageNamed:@"tabbar.png"]]];

[tab.tabBarinsertSubview:mViewatIndex:1];

mView.alpha=0.8;

5.如何隐藏系统自带的tabbar

有时候有的页面并不需要显示tabbar,但是返回的时候要显示tabbar,举个例子A->B 当A push到 B 时需要设置self.navigationController.hidesBottomBarWhenPushed= YES;

同时在B页面要

- (void)viewWillAppear:(BOOL)animated

{

[superviewWillAppear:animated];

self.tabBarController.tabBar.hidden=YES;

}

- (void)viewWillDisappear:(BOOL)animated

{

[superviewWillDisappear:animated];

self.tabBarController.tabBar.hidden=NO;

}

你可能感兴趣的:(设置NavigationBar和UITabBarItem的属性)