I have a UITableViewCell which has two UITextFields (without borders). The following constraints are used to set up the horizontal layout.
@"|-10-[leftTextField(>=80)]-(>=10)-[rightTextField(>=40)]-10-|"
Nothing fancy, and works as expected.
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.
I don't like that, the width of the textField should adjust while the user types into that textField.
In my opinion that should work out of the box. By implementing a IBAction
for the UIControlEventEditingChanged
event I can confirm that typing actually changes the intrinsicContentSize
of the UITextField.
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.
These commented out lines is what I tried without any success:
- (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));
}
Does anybody know what I am missing? What could I try to make this work?