Note that there are some explanatory texts on larger screens.

plurals
  1. POResize a UITextField while typing (by using Autolayout)
    primarykey
    data
    text
    <p>I have a UITableViewCell which has two UITextFields (without borders). The following constraints are used to set up the horizontal layout. </p> <p><code>@"|-10-[leftTextField(&gt;=80)]-(&gt;=10)-[rightTextField(&gt;=40)]-10-|"</code></p> <p>Nothing fancy, and works as expected. </p> <p><img src="https://i.stack.imgur.com/Fs0he.png" alt="enter image description here"></p> <p>As you can see the upper textField has the correct size. The lower textField started with an empty text, and because of the empty text it is 80 points wide. When I type text into the editing textField the text scrolls to the left, it does not change its width. </p> <p>I don't like that, the width of the textField should adjust while the user types into that textField. </p> <p>In my opinion that should work out of the box. By implementing a <code>IBAction</code> for the <code>UIControlEventEditingChanged</code> event I can confirm that typing actually changes the <code>intrinsicContentSize</code> of the UITextField. </p> <p>But well, the width does not change until the textField is no longer the first responder. If I put the cursor into another textField the width of the edited textField is set. That's a bit late for what I want. </p> <p>These commented out lines is what I tried without any success: </p> <pre><code>- (IBAction)textFieldDidChange:(UITextField *)textField { [UIView animateWithDuration:0.1 animations:^{ // [self.contentView removeConstraints:horizontalConstraints]; // [self.contentView addConstraints:horizontalConstraints]; // [self.contentView layoutIfNeeded]; // [self.contentView setNeedsLayout]; // [self.contentView setNeedsUpdateConstraints]; }]; NSLog(@"%@", NSStringFromCGSize(textField.intrinsicContentSize)); } </code></pre> <p>Does anybody know what I am missing? What could I try to make this work? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload