In a UIToolbar
,我添加了一个UITextField
到栏的中间(它被添加为UIBarButtonItem
) 和另外一个UIBarButtonItem
(操作按钮)在它旁边。我在最左边和最右边添加了灵活的空格键按钮项目。它在纵向上看起来很棒,但是当我旋转到横向时,它会居中并且看起来不错,但我需要拉伸文本字段以填充宽度并将最后一个按钮向右推 - 与消息中的完全一样 - 在iPhone 和 iPad。
我认为自动布局可以解决问题,但苹果声明你不能为UIBarButtonItem
s。事实上,当我选择任何栏按钮或文本字段时,它不允许创建任何约束。
您能让我知道如何实现这一目标吗?谢谢!
EDIT: I've tried a few other combinations with fixed/flexible spaces. When I don't add any, the text field and share button are pushed over to the left:
相反,如果我使用固定空格,它看起来与上面的 0 宽度完全相同,或者如果我设置一个宽度,那么它显然会将它们推倒。最右边的最后一个空格没有任何效果——它没有固定在最右边,所以它会离开屏幕。
I tried a fixed space on the left and a flexible on the right, with the middle one fixed (or no middle one), and it looks like the screenshot above. I then changed the middle one to flexible and it turned out like this:
If I change the first to flexible, none in the middle (or if I add a fixed one), and flxed on the right, it is moved over to the right:
If the first is flexible, middle is flexible, and right is fixed, this is how it looks:
在所有情况下,文本字段的宽度都保持与故事板中最初设置的静态值相同。我认为问题在于,当您通过拖动框架来设置宽度时,没有可以捕捉的蓝色参考线,因此它将始终保持相同的宽度。
我是否错过了任何空格组合?如果我无法在界面生成器中实现所需的行为,那么如何在代码中实现这一目标?