NavigationBar设置
- 设置背景颜色
[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
- Translucent设置成透明度,设置成YES会有一种模糊效果
[self.navigationController.navigationBar setTranslucent:YES];
- 设置背景图片,图片样式需要根据情况适用
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"FlyElephant.png"] forBarMetrics:UIBarMetricsDefault];
- 设置NavigationBar标题大小及颜色
之前设置是通过UITextAttributeFont,UITextAttributeTextColor,UITextAttributeTextShadowColor和UITextAttributeTextShadowOffset设置,现在需要都根据NS开头的属性去设置
NSDictionary *textAttributes=@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:20]};
[self.navigationController.navigationBar setTitleTextAttributes:textAttributes];
- NavigationBar设置中间的标题或者自定义View
[self.navigationItem setTitle:@"旅行"];
[self.navigationItem setTitleView:[UIImage imageNamed:@"FlyElephant"];
- 单个或多个左右Item设置
//单个leftItem设置:
UIBarButtonItem *leftBarButton=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"BackIcon"] style:UIBarButtonItemStylePlain target:self action:@selector(popBack)];
[leftBarButton setTintColor:[UIColor colorWithWhite:0 alpha:1]];
self.navigationItem.leftBarButtonItem=leftBarButton;
//多个rightItem设置:
UIBarButtonItem *firstItem=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:nil];
UIBarButtonItem *secondItem=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:nil];
NSArray *rightItems=@[firstItem, secondItem];
self.navigationItem.rightBarButtonItems=rightItems;