关于自定义导航条UIBarButtonItem偏移的问题
2015-08-08 19:24
351 查看
在自定义导航条左按钮的时候发现按钮的位置向右偏移,下面给出了解决方法
主要还依赖于UIButton的属性设置
// 设置导航条的左按钮
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton.frame = CGRectMake(0, 0, 32, 26);
leftButton.imageEdgeInsets = UIEdgeInsetsMake(0, -13, 0, 0);// 设置按钮图片的偏移位置(向左偏移)
[leftButton setImage:[UIImage imageNamed:@"shouye-cehua"] forState:UIControlStateNormal];
[leftButton addTarget:self action:@selector(handleLeftButtonAction:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
主要还依赖于UIButton的属性设置
// 设置导航条的左按钮
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton.frame = CGRectMake(0, 0, 32, 26);
leftButton.imageEdgeInsets = UIEdgeInsetsMake(0, -13, 0, 0);// 设置按钮图片的偏移位置(向左偏移)
[leftButton setImage:[UIImage imageNamed:@"shouye-cehua"] forState:UIControlStateNormal];
[leftButton addTarget:self action:@selector(handleLeftButtonAction:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
相关文章推荐
- UIButton以及UITextField
- [LeetCode]N-Queens 八皇后问题扩展(经典深层搜索)
- Reveal UI 分析工具简单使用
- Codeforces 566 F. Clique in the Divisibility Graph
- iOS开发UI篇—CAlayer层的属性
- UIViewController - View Management(视图管理)
- sendRedirect和getRequestDispatcher的一些区别
- UIScrollView+UIView无法点击
- ibatis的queyrForList和queryForMap区别
- Equidistant String (周赛2)
- UI06_UIPageControl
- 杭电 1711 Number Sequence(kmp)
- UITextField(loading...)
- 使用StoryBoard做IOS UI界面跳转
- Android 蓝牙4.0 Bluetooth BLE 写数据(修改BLE设备的属性)
- UI06_UIScrollView
- 杭电1711Number Sequence
- 找不到类FeatureQuery解决办法
- RESTful API URI 设计: 查询(Query)和标识(Identify)
- Android中使用Build获取当前系统SDK版本