iOS - 导航栏UINavigationController常用属性
2015-07-30 09:55
357 查看
1.设置导航栏标题
self.title = @"dylan_李伟宾";
2.设置导航栏样式
设置方法:[self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];
UIBarStyle的样式:
typedef NS_ENUM(NSInteger, UIBarStyle) { UIBarStyleDefault = 0, UIBarStyleBlack = 1, UIBarStyleBlackOpaque = 1, // Deprecated. Use UIBarStyleBlack UIBarStyleBlackTranslucent = 2, // Deprecated. Use UIBarStyleBlack and set the translucent property to YES };
UIBarStyleDefault是默认样式,
UIBarStyleBlack是黑色不透明。
UIBarStyleBlackOpaque和
UIBarStyleBlackTranslucent这两个已经废弃了。
如果想设置导航栏透明,可以加上下面这句代码:
self.navigationController.navigationBar.translucent = YES;
3.修改返回按钮title
self.navigationItem.title = @"test";
4.隐藏返回按钮title
比较笨的方法是:self.navigationItem.title = @"";
还可以这样设置:
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
5.设置leftBarButtonItem
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStylePlain target:self action:@selector(back:)]; - (void)back:(id)sender { [self.navigationController popViewControllerAnimated:YES]; }
6.左滑返回手势失效了怎么办
如果按上一步设置leftBarButtonItem之后,左滑返回手势就会失效。设置一下
UIGestureRecognizerDelegate代理即可:
self.navigationController.interactivePopGestureRecognizer.delegate = self;
相关文章推荐
- UIlabel 获取高度
- LeetCode OJ 之 Implement Queue using Stacks(使用栈实现队列)
- UILabel attributedText
- 解决:Requested 'libdrm_radeon >= 2.4.56' but version of libdrm_radeon is 2.4.52
- UILabel UI中添加文字框
- 猜拳游戏GuessGame源码
- 猜拳游戏GuessGame源码
- Optimal ArrayMultiplication Sequence
- requiredJS----AMD模块加载器
- LeetCode——Implement Queue using Stacks
- UISearchBar的介绍以及蒙板的主流使用
- Servlet请求转发 RequestDispatcher接口知识点
- UIKit 带属性的字符串 NSAttributedString、NSMutableAttributedString、NSTextStorge(未完成)
- 基于Spacebuilder开发问题汇总
- MicroservicePrerequisites
- Unique Binary Search Trees
- C# string与StringBuilder的不同
- Snail—UI学习之文本编辑视图UITextView
- Snail—UI学习之进度条UIProgressView
- iOS UI01_Label