Resize a text field when entering large text

In my application, I have several textField. when I enter a small text, than it will work fine, but when a large text will be entered, than the size of the text field has changed.

Like this

With a little text

enter image description here

With big text

enter image description here

And yes, this is only in iOS6, not iOS5.

UPDATE

I do not know how to do this, but I changed the restriction property on the ios6 screen and now it will work fine. Thanx for your help.

+4
source share
4 answers

try it

[yourTextField setAdjustsFontSizeToFitWidth:FALSE]; 
0
source

Try using this option. But UITextField does not provide any option for creating a multi-line text field. So you have to go with a UITextView .

 - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { CGSize size = [txtView.text sizeWithFont:txtView.font]; CGRect f = txtView.frame; f.size.height = ceil(size.width/f.size.width)*size.height; txtView.frame = f; } 

And for more information ..

Otherwise, if you do not want to do the next line, use this code.

 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { CGSize boundingSize = CGSizeMake(320, CGFLOAT_MAX); CGSize requiredSize = [textField.text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:20.0f] constrainedToSize:boundingSize lineBreakMode:NSLineBreakByWordWrapping]; CGFloat requiredHeight = requiredSize.height; CGRect frame1; frame1 = txtFld.frame; frame1.size.height = requiredHeight; txtFld.frame = frame1; NSLog(@"%f", frame1.size.height); return YES; } 
0
source

if you do not want to change the width, you can limit it to textField.frame.size.width

properties.

which means that after expanding to a certain width, limit the input

0
source

I faced the same problem. I had to set the left and right limits of my text box and its neighboring uilabel so that my text box would not change when I entered a lot of text. This is a problem with Autolayout. Tried all of the above solutions, can not be fixed by the above solutions.

0
source

Source: https://habr.com/ru/post/1485029/


All Articles