I am working on an ios application using autolayout,
I have a UITextField and a UIButton next to it horizontally.
The UIButton text is changed dynamically. It can be very short (3 letters) or very long (15 letters)
I need to add constraint to achieve the following:
1) when I change the UIbutton text, I need the button to resize to fit the new text
2) the UITextField should resize to take the available space left after the button text change
I tried to do the following (like shown in the picture):
Added a leading constraint for the UITextView to the superview 20
Added a trailing constraint for the UIButton to the superview 20
Added a fixed distant between them 10
but now I'm stuck on how to make the UIButton resize with the text and the textfield to take the available size.
Any help is appreciated
Thank you
Try these autolayout constraints:
UITextField
object's width constraint should be a Less Than or Equal
relationUIButton
object's width constraint should be a Greater Than or Equal
relationUITextField
object's horizontal Content Hugging Priority
should be 249 (as per my constraint settings shown above)And related code as:
[buttonObject setTitle:@"Button title is too... zzz" forState:UIControlStateNormal];
[buttonObject sizeToFit];
...or something along these lines
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With