4

In my app I have multiple textField. when I enter small text than it will work fine, but when large text is entered than textField size changed.

Like this

With small text

enter image description here

With large text

enter image description here

And yes its only happen in iOS6 not in iOS5.

UPDATE

I dont know how to but i have change my constraint property in ios6 screen and it will now run fine. Thanx for your help.

4 Answers4

0

Try this

[yourTextField setAdjustsFontSizeToFitWidth:FALSE];
Prashant Nikam
  • 2,253
  • 4
  • 17
  • 29
  • do you mean that fontsize of the uitexfield is changing i.e. getting smaller..? – Prashant Nikam Jun 07 '13 at 12:28
  • No as you can see if i enter large amount of text than textfield's width also increase. thats i dont want to i want textfield default effect of hiding charecter with ... sign –  Jun 07 '13 at 12:37
0

Try to use this one.But UITextField doesn't provide any option to make it multi-lined text box. So you have to go with 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 info..

  1. How to create a multiline UITextfield?

Otherwise if you don't wanna make in next line then 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;
}
Community
  • 1
  • 1
Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
0

if you dont want to change the width then you can restrict it by textField.frame.size.width

property.

that means after extending to some width ,restrict to input

Ravindra Bagale
  • 17,226
  • 9
  • 43
  • 70
0

I faced the same problem too. I had to set the left and right constraint of my text field and its adjacent uilabel to ensure my text field doesn't resize itself after entering large amount of text. This is a issue with Autolayout. Tried all the above solutions, can't be fixed by above solutions.

Manoj Kumar
  • 318
  • 4
  • 14