我有一个 UIBarButtonItem
和一个 UIView
包含两个 UITextField
控件,都在 UIToolbar
中.
这是我的 Storyboard的截图:http://i.8px.co/x8eC.png .
我想创建类似这样的东西:http://i.8px.co/1hvY.png .
我正在尝试制作 UIView
及其子项扩展以填充 UIToolbar
中的可用水平空间使用自动布局。我不知道如何完成我想要的。
我为 UIView 尝试了一个肮脏的解决方案,并且能够让它的大小稍微正确一些。
view.width = toolBar.frame.width - button.width
// where view is the UIView, toolBar is the UIToolBar, and button is the UIBarButtonItem
我不认为这很优雅。这是以编程方式完成的,UIView
不符合标准 UIToolbar
边距,解决方案不适用于 UITextFields
.
最佳答案
恐怕您必须以编程方式执行此操作。
试试这个:
self.toolBarview.frame = (CGRect) {.origin = self.toolBarview.frame.origin.x, self.toolBarview.frame.origin.y, .size = [UIScreen mainScreen].bounds.size.width - self.barButton.width - 40, self.toolBarview.frame.size.height};
这里的 toolBarview 是 UIView,它有 2 个 UITextField。 40 是您需要减去以提供填充的缓冲区值。
/* 编辑 */
您应该为 UITextField
提供适当的约束,如下所示:
关于ios - 使用自动布局使 UIView 和内容扩展以填充 UIToolbar 中的可用水平空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32131432/