关于navigationBar.leftBarItem按钮点击范围太大的问题
2015-09-07 16:52
405 查看
今天发现如果直接在leftBarItem添加一个自定义button的时候,
这个button的有效点击范围将会很大,接近navigationBar的titleview。
有时候我们不想要这种特性(关键是产品经理可能不想要这么大的点击范围)。可以这样做:
先将你的leftBarItembutton添加到一个同样大小的uiview中,然后再将这个uiview添加到leftBarItem里。
代码如下
UIImage *backImg = [UIImage imageNamed:imageName];
UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0.f, 0.f, backImg.size.width, backImg.size.height)];
[backBtn setImage:backImg forState:UIControlStateNormal];
UIView *backBtnView = [[UIView alloc] initWithFrame:backBtn.bounds];
backBtnView.bounds = CGRectOffset(backBtnView.bounds, -6, 0);
[backBtnView addSubview:backBtn];
UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc] initWithCustomView:backBtnView];
self.navigationItem.leftBarButtonItem = backBarBtn;
这个button的有效点击范围将会很大,接近navigationBar的titleview。
有时候我们不想要这种特性(关键是产品经理可能不想要这么大的点击范围)。可以这样做:
先将你的leftBarItembutton添加到一个同样大小的uiview中,然后再将这个uiview添加到leftBarItem里。
代码如下
UIImage *backImg = [UIImage imageNamed:imageName];
UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0.f, 0.f, backImg.size.width, backImg.size.height)];
[backBtn setImage:backImg forState:UIControlStateNormal];
UIView *backBtnView = [[UIView alloc] initWithFrame:backBtn.bounds];
backBtnView.bounds = CGRectOffset(backBtnView.bounds, -6, 0);
[backBtnView addSubview:backBtn];
UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc] initWithCustomView:backBtnView];
self.navigationItem.leftBarButtonItem = backBarBtn;
相关文章推荐
- 如何让一个DIV浮动在另一个DIV上面
- Mutillidae在kali linux上的安装
- 已知局域网IP地址,如何查看mac
- 桌面支持--outlook.com怎么设置pop3接收邮件
- CSDN第一篇
- *p++和*++p的区别
- URLClassLoader源码笔记
- Unity3D: NGUI自定义Atlas,Font
- 1219 -- 扑克牌
- 1218 -- 高精度加法
- 学习vagrant
- 1.3 对话框透明度
- JNI完全手册
- Windows下编译Caffe并编译Matlab接口
- Java____SpringMVC教学资源(坑)
- 桌面支持-设置adobe为默认pdf阅读软件方式
- matlab高手博客记录
- 第2周项目0-宣告“主权”
- 脚本乐园 Shell中命令行选项和参数的处理
- 禁止tomcat生成catalina.out、localhost_access_log、host-manager.log、localhost.log、manager.log这些文件