NavigationBar设置

NavigationBar设置

  1. 设置背景颜色
[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
  1. Translucent设置成透明度,设置成YES会有一种模糊效果
[self.navigationController.navigationBar setTranslucent:YES];
  1. 设置背景图片,图片样式需要根据情况适用
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"FlyElephant.png"] forBarMetrics:UIBarMetricsDefault];
  1. 设置NavigationBar标题大小及颜色

之前设置是通过UITextAttributeFont,UITextAttributeTextColor,UITextAttributeTextShadowColor和UITextAttributeTextShadowOffset设置,现在需要都根据NS开头的属性去设置

NSDictionary  *textAttributes=@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:20]};

[self.navigationController.navigationBar setTitleTextAttributes:textAttributes];
  1. NavigationBar设置中间的标题或者自定义View
[self.navigationItem setTitle:@"旅行"];
[self.navigationItem setTitleView:[UIImage imageNamed:@"FlyElephant"];
  1. 单个或多个左右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;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容