iOS 自动布局和 UIToolbar/UIBarButtonItems

iOS Autolayout and UIToolbar/UIBarButtonItems(iOS 自动布局和 UIToolbar/UIBarButtonItems)

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

问题描述

我有一个启用了自动布局的 iOS 视图,并且有一个 UIToolbar 和一个 UISearchBarUISegmentControl 包含在工具栏上.我希望 UISearchBar 具有灵活的宽度,因此我需要添加一个约束来强制执行此操作,但据我所知,您不能向 UIToolbar 中的项目添加约束界面生成器.选项全部禁用.

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.

AutoLayout 之前,我会使用 autoresizingmasks 来完成.

Before AutoLayout I would accomplish this with autoresizingmasks.

UIToolbars/UINavigationBars中是否不允许有约束?

在使用自动布局时还能如何实现?

How else can this be accomplished when using autolayout?

推荐答案

自动布局约束仅适用于 UIViews 及其子类.

Autolayout constraints only work with UIViews and their subclasses.

虽然 UIToolbar 允许一些基于 UIView 的项目(例如 UISearchBarUISegmentedControl),但它们可能必须共存使用不继承自 UIViewUIBarButtonItems.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:iOS 自动布局和 UIToolbar/UIBarButtonItems

基础教程推荐