向 UIBarButtonItem 添加约束 [英] Adding constraints to a UIBarButtonItem

查看:28
本文介绍了向 UIBarButtonItem 添加约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode 不允许我在 MainStoryBoard 中的 ViewController 上对 BarButtonItem 施加约束.如图所示,它显示在不可读的左侧太远.

Xcode is not allowing me to put constraints on my BarButtonItem on a ViewController in the MainStoryBoard. It's appearing too far to the left where it's unreadable as shown in the image.

下图显示了 BarButtonItem 的位置.它应该说项目".我还查看了 Xcode 上的预览分屏,它在 iPhone6 上看起来不错,但在 iPhone 4 上却不行(它在 iPhone 4 上被剪掉了一半,但在这里它被剪掉了 3/4s).在这里,我正在为 iPhone 6 运行,我明白了.

The image below shows where the BarButtonItem is. It's supposed to say "Item". I also looked on the preview split screen on Xcode and it looked fine for the iPhone6 but not for the iPhone 4 (it's half cut on the iPhone 4 but here its 3/4s cut). Here I'm running for the iPhone 6 and i get that.

如何在 Xcode 中添加约束或如何以编程方式将约束添加到此 BarButtonItem?

How do I add constraints in Xcode or how do I add the constraints programmatically to this BarButtonItem?

非常感谢任何帮助.

推荐答案

在您的 xib/故事板中拖放导航栏

Drag and drop navigation bar in your xib / story board

您可以根据您的要求向此导航栏添加约束.

U can add constraints to this navigation bar as per your requirement.

然后将 Bar Button Item 添加到导航栏

Then add Bar Button Item to your navigation bar

Bar Button Item 采用默认位置,您不能在此处合并自动布局.

Bar Button Item takes it default position u cannot incorporate autolayout there.

虽然如果你想要固定或灵活的条形按钮项目的位置,你可以使用固定的空格键按钮项目或灵活的空格键按钮项目.

Although if u want positions of Bar Button Item Fixed or Flexible u can make use of Fixed Space Bar Button Item or Flexible Space Bar Button Item.

如果位置是固定的,则在两个 Bar Button Item 之间拖动 Fixed Space Bar Button.如果位置不固定,则在您的两个 Bar Button Item 之间灵活拖动 Flexible Space Bar Button Item.

If positions are fixed drag Fixed Space Bar Button between your two Bar Button Item's. And if positions is not fixed its flexible drag Flexible Space Bar Button Item between your two Bar Button Item's.

编码愉快.. :)

这篇关于向 UIBarButtonItem 添加约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆