UIBarButtonItem改变系统rightbutton和leftbutton的位置
2015-11-15 15:12
369 查看
由于系统的UIBarButtonItem *rightButton和UIBarButtonItem *rightButton的位置已经固定,但有时我们又想改变他的位置,可以这么做
// 设置右边的按钮
UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
[rightBtn setImage:[UIImage imageNamed:@"white_Cart"] forState:UIControlStateNormal];
[rightBtn addTarget:self action:@selector(clickRightBtn) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSpacer.width = -15.0; // 这样rightButton就会向右移动15,也就是更接近边框了
self.navigationItem.rightBarButtonItems = @[negativeSpacer, rightButton];
// 设置右边的按钮
UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
[rightBtn setImage:[UIImage imageNamed:@"white_Cart"] forState:UIControlStateNormal];
[rightBtn addTarget:self action:@selector(clickRightBtn) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSpacer.width = -15.0; // 这样rightButton就会向右移动15,也就是更接近边框了
self.navigationItem.rightBarButtonItems = @[negativeSpacer, rightButton];
相关文章推荐
- UI之textField文本框
- Android线程间通信(二):MessageQueue(上)
- UIbutton
- UITabBarController简单介绍
- dojo/io-query源码解析
- jsp Request获取url信息的各种方法比较
- UIColor
- 关于request.getParameterMap()的类型转换和数据获取
- iOS--UIScrollView基本用法和代理方法
- Machine Learning week 2 quiz: Octave Tutorial
- LCS修改版(Longest Common Subsequence 最长公共子序列)
- 基于CefGlue的桌面应用开发
- 使用Easyui pagination分页控件进行分页
- hdoj 4000 Fruit Ninja 【树状数组 + 思维】
- ns ui开头的类的含义
- Machine Learning week 2 quiz: Linear Regression with Multiple Variables
- mcc,mex,mbuild
- LeetCode OJ:Range Sum Query - Immutable(区域和)
- iOS UILabel根据文字获取高度及UITableCell动态获取高度(以截取快递信息为例)
- UI之button基础