How I can set the Auto resize in Text Field in iOS ?
helloWorld.m
self.TextFieldExample.text = @"HELLO WORLD HELLO WORLD HELLO WORLD HELLO WORLD";
Now:
HELLO WORLD HELLO ...
Correct:
HELLO WORLD HELLO WORLD HELLO WORLD HELLO WORLD
What is the best practice in this case?
You should add an action executed by the textField
of type Editing Changed
and inside this action you should add [self.textField sizeToFit];
like this:
- (IBAction)textChanged:(UITextField *)sender {
[self.textField sizeToFit];
}
This way every time that the contents of your Text Field changed it will execute the action and it will resize to the length of your text.
And if you want the text to resize to fit the width of your textField, you can do that in the attributes inspector of the storyboard: http://i.stack.imgur.com/udVlk.png
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