加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 如何调整rightBarButtonItems中两个UIBarButtonItem之

发布时间:2020-12-15 01:45:48 所属栏目:百科 来源:网络整理
导读:我使用以下代码将两个按钮添加到self.navigationItem.rightBarButtonItems,我认为在iOS7中,两个按钮之间的空间太宽,有没有办法减少这两个按钮之间的空间? UIBarButtonItem *saveStyleButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:
我使用以下代码将两个按钮添加到self.navigationItem.rightBarButtonItems,我认为在iOS7中,两个按钮之间的空间太宽,有没有办法减少这两个按钮之间的空间?

UIBarButtonItem *saveStyleButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"save.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(saveStyle)];

UIBarButtonItem *shareStyleButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(shareStyle)];

NSArray *arr= [[NSArray alloc] initWithObjects:shareStyleButton,saveStyleButton,nil];

self.navigationItem.rightBarButtonItems=arr;

欣赏任何提示或想法.

解决方法

2015年7月更新

更好的方法是使用storyboard(在Xcode 6.4中测试).首先,添加一个UINavigationItem;其次,添加一个条形按钮项;第三,将视图添加到刚刚在步骤2中创建的条形按钮项;第四,在你刚刚拖入的视图中添加任意数量的按钮;最后,用鼠标和约束调整空间.

相关问题

Can’t assign multiple Buttons to UINavigationItem when using Storyboard with iOS 5

How to add buttons to navigation controller visible after segueing?

旧答案(仅适用于小插图)

使用imageInsets属性:

leftButton.imageInsets = UIEdgeInsetsMake(0.0,0.0,-15);
rightButton.imageInsets = UIEdgeInsetsMake(0.0,-15,0);

对于三个或更多按钮,中间的按钮得到两个插图:

leftButton.imageInsets = UIEdgeInsetsMake(0.0,-15);
middleButton.imageInsets = UIEdgeInsetsMake(0.0,0);

对于右侧按钮,请注意:项目数组中的FIRST按钮是正确的:

rightButton.imageInsets = UIEdgeInsetsMake(0.0,0);
middleButton.imageInsets = UIEdgeInsetsMake(0.0,-15);
leftButton.imageInsets = UIEdgeInsetsMake(0.0,-15);

重要提示:拆分两个邻居之间的插图;如果将整个插图应用到一个边缘,很明显按钮在“空白”空间中重叠 – 一个按钮获得所有“间隙”触摸.即使将这样的调整“分开”,两边都是-40,水龙头肯定会出现错误按钮. -15或-20是使用此技术时最常考虑的.

通过应用此方法,按钮甚至可以在四个方向上移动.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读