Reputation: 660
In my storyboard, my view controller has two container views as shown below
The second container view is it tone am having difficulty setting constraints for.
When I actually run the app, the text field, becomes very narrow. My horizontal constraints are obviously incorrect but I can't figure out the right settings.
Here what I currently have:
FilterIcon - trailing space to superview (right): 0
- Align Center Y
- Leading space to "Go": 16
- Equal height to text box
Go Button - align center Y
- trailing space to filter icon: 16
- leading space to text box: 8
Text Box - leading space to superview (left): 0
- trailing space to Go Button: 8
- equal height to Filter icon
- horizontal hugging priority: highest of 3 elements 751
I thought the text box would expand from the left margin until it reached the Go box which is set to the right based on the filter icon.
What am I missing for the constraints?
Upvotes: 3
Views: 265
Reputation: 413
How about configuring like this?
Text Box
Go Button
Filter Icon
Here is my screenshot.
If you don't want to set priorities, you can just set width constraints for both Filter Icon and Go Button. For more information, there is very good tutorial about content hugging priority and compression resistance priority in here
Upvotes: 1
Reputation: 3358
Give aspect ratio to the text field for its width and height and give center y to superview. This will definitely work. But make sure when you give aspect ratio, your text field is having the width you require.
Upvotes: 0
Reputation: 1
I think you can set both buttons' height equal to width. Then other space is left to the text field.
Upvotes: 0