使用customView创建一个UIBarButtonItem就像Flexible-Space项一样

问题描述:

我的 UIBarButtonItem 有一个 UITextField 作为其customView。工具栏包含此项目和几个按钮。

I have a UIBarButtonItem that has a UITextField as its customView. The toolbar contains this item and a few buttons.

当工具栏调整大小时(比如设备方向更改)我想要 UITextField 增长或缩小(宽度)以占用工具栏中的所有可用空间。

As the toolbar resizes (say on a device-orientation change) I want the UITextField to grow or shrink (width) to occupy all the available space in the toolbar.

不知道所有按钮的组合大小工具栏,然后适当地设置 UITextField 宽度,是否有一些神奇的方法使这个项目像灵活空格条项目?

Short of figuring out the combined sizes of all the buttons in the toolbar, then setting the UITextField width appropriately, is there just some magical way to make this item behave like a flexible-space bar item?

如果将 UIViewAutoresizingFlexibleWidth 设置为文本字段,它应自动缩小或增长。

If you set UIViewAutoresizingFlexibleWidth to your textfield it should automatically shrink or grow.