问题描述
我启用了自动布局在iOS视图,并有一个 UIToolbar
与的UISearchBar
和 UISegmentControl
载带的工具栏。我想在的UISearchBar
有一个灵活的宽度,所以我需要添加约束,迫使这一点,但我可以告诉你不能在<$ C添加约束项$ C> UIToolbar 在Interface Builder。这些选项均无效。
I have an iOS view with autolayout enabled and have a UIToolbar
with a UISearchBar
and UISegmentControl
contained with the toolbar. I want the UISearchBar
to have a flexible width so I need to add a constraint to force this, but from what I can tell you cannot add constraints to items in a UIToolbar
in Interface Builder. The options are all disabled.
在自动版式
我将与 autoresizingmasks
做到这一点。
不到 UIToolbars / UINavigationBars
?
还能如何使用自动布局时可能?
How else can this be accomplished when using autolayout?
推荐答案
自动布局的限制只能用 UIViews
及其子类的工作。
Autolayout constraints only work with UIViews
and their subclasses.
在 UIToolbar
允许一些的UIView
根据项目(如的UISearchBar
和 UISegmentedControl
),它们可能与共存 UIBarButtonItems
不从 UIView的。
While UIToolbar
allows some UIView
based items (such as UISearchBar
and UISegmentedControl
) they may have to coexist with UIBarButtonItems
which do not inherit from UIView
.
直到自动布局可以用 UIBarButtonItems
工作,做你做的事。
Until autolayout can work with UIBarButtonItems
, do as you have done.
您的选择是与仅基于 UIViews
部件推出自己的工具栏。
Your alternative is to roll your own toolbar with widgets based only on UIViews
.
这篇关于iOS的自动布局和UIToolbar / UIBarButtonItems的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!