iOS的自动布局和UIToolbar / UIBarButtonItems [英] iOS Autolayout and UIToolbar/UIBarButtonItems

查看:397
本文介绍了iOS的自动布局和UIToolbar / UIBarButtonItems的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我启用了自动布局在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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