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..
- 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;
}