UINavigationItem的那点事
2015-11-03 11:36
591 查看
有些时候在设置UINavagationItem的时候我也许会用到自己的图片来设置leftBarButtonItem和rightBarButtonItem,或者是标题。在这不啰嗦了,直接上代码示例:
// 用自定义的view来替换标题 @property(nullable, nonatomic,strong) UIView *titleView; // 左、右标题 @property(nullable, nonatomic,strong) UIBarButtonItem *leftBarButtonItem; @property(nullable, nonatomic,strong) UIBarButtonItem *rightBarButtonItem; // UIBarButtonItem父类(UIBarItem)的属性,用来修改item的位置 @property(nonatomic) UIEdgeInsets imageInsets; // default is UIEdgeInsetsZero // 示例 // 左右标题位置设置 UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:imageName] style:UIBarButtonItemStylePlain target:self action:nil]; leftItem.imageInsets = UIEdgeInsetsMake(0, 0, 12, 0); // UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>) self.navigationItem.leftBarButtonItem = leftItem; // titleView位置,在这有个专门的方法来设置他的上下位置 - (void)setTitleVerticalPositionAdjustment:(CGFloat)adjustment forBarMetrics:(UIBarMetrics)barMetrics; // 这里我是用[UINavigationBar appearance]调出程序所有的UINavigationController 在appdaelegate.m 里面同一添加设置(UINavigationController通用的属性都可以统一设置) [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:-12 forBarMetrics:UIBarMetricsDefault];
相关文章推荐
- android 代码实现控件之间的间距
- [Android]在代码里运行另一个程序的方法
- 肯特·贝克:改变人生的代码整理魔法
- 网页恶意代码的预防
- 高手写的Tracer-Flash代码调试类代码下载
- CSS代码缩写技巧
- 非主流Q-zOne代码代码搜集第1/2页
- CreateWeb.vbs 代码
- Lua中编译执行代码相关的函数详解
- 更有效率的css代码编写第1/3页
- 代码中到底应不应当写注释?
- SQL语言查询基础:连接查询 联合查询 代码
- 论坛头像随机变换代码
- .NET 常用功能和代码小结
- C#实现压缩HTML代码的方法
- asp编程中常用的javascript辅助代码第1/2页
- C#超实用代码段合集
- Javascript代码在页面加载时的执行顺序介绍
- JS实现图片无间断滚动代码汇总
- 我的论坛源代码(二)