大佬教程收集整理的这篇文章主要介绍了iphone – 如何调整rightBarButtonItems中两个UIBarButtonItem之间的空间,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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;
欣赏任何提示或想法.
更好的方法是使用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是使用此技术时最常考虑的.
通过应用此方法,按钮甚至可以在四个方向上移动.
以上是大佬教程为你收集整理的iphone – 如何调整rightBarButtonItems中两个UIBarButtonItem之间的空间全部内容,希望文章能够帮你解决iphone – 如何调整rightBarButtonItems中两个UIBarButtonItem之间的空间所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。