使用customView创建一个UIBarButtonItem就像Flexible-Space项一样 [英] make a UIBarButtonItem with customView behave like Flexible-Space item
问题描述
我的 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.
这篇关于使用customView创建一个UIBarButtonItem就像Flexible-Space项一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!