IOS7适配之:返回按钮偏移问题
来源:互联网 发布:sqlplus导出sql脚本 编辑:程序博客网 时间:2024/05/18 09:10
IOS7下用系统的UIBarButtonItem时返回按钮左边距比IOS6小,见下图:
图1:上面是IOS6,下面是IOS7
需求:
IOS6和IOS7的返回按钮要统一成IOS7样式的,即偏移量要像下面那个图那么宽,那IOS6怎么办呢?
解决方案:
#define IOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)+ (UIBarButtonItem *)backItem{UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:STR_button_backItem] forState:UIControlStateNormal]; button.backgroundColor = [UIColor clearColor]; CGFloat offset = 8; if (IOS7) { offset = 0; } button.frame = CGRectMake(offset, 0, kBackButtonWidth, kBackButtonHeight); UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kBackButtonWidth+offset, kBackButtonHeight)]; button.tag = 147; [aView addSubview:button]; aView.userInteractionEnabled = YES; UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:aView]; return backItem;}- (void)setTarget:(id)target action:(SEL)action{ UIButton *buttom = (UIButton *)[(self.customView) viewWithTag:147];[buttom addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];} //设置导航栏返回按钮 UIBarButtonItem *backButton = [UIBarButtonItem backItem]; [backButton setTarget:self action:@selector(backButtonItemClick)]; self.navigationItem.leftBarButtonItem = backButton;
希望对大家有帮助~!~!
0 0
- IOS7适配之:返回按钮偏移问题
- 自定义返回按钮偏移问题
- IOS 之iIOS11更新 导航返回按钮偏移的问题。。。。。
- 自定义返回按钮时,iOS7手势返回遇到的问题
- 自定义返回按钮时,iOS7手势返回遇到的问题
- IOS 11导航返回按钮偏移的问题
- iOS11NavigationItem偏移,iOS11适配问题,iOS11导航栏返回偏移,iOS11BarButtonItem偏移,Xcode9遇见的问题
- iOS7 custom leftBarButtonItem 偏移问题
- ios7以上,导航栏的按钮会出现向中间偏移问题的解决方法
- ios7导航栏返回按钮的一些问题总结
- iOS11项目适配 UIScorllView下移和导航栏返回按钮偏移
- IOS7 系统下的UIScrollView偏移问题
- iOS7 initWithCustomView- leftBarButtonItem / rightBarButtonItem 偏移问题
- iOS7 适配问题
- iOS7适配问题
- iOS7适配问题
- ios7适配问题
- iOS7适配问题
- 地产股跌幅高达
- 管道通信
- 网络分析之转弯要素(Turn Features)
- 一个遮罩层
- ubuntu 13.04 安装sougou输入法。
- IOS7适配之:返回按钮偏移问题
- 构造方法重载和调用
- ubuntu下忘记mysql root 密码
- svn update老报错
- Win7下硬盘安装Ubuntu12.04双系统
- 一个原生js操作Ajax封装
- CLBLAS build
- 看代码猜古诗哈哈逗死我了
- NoSQL数据库探讨之 —— 为什么要用非关系数据库?