matthew
matthew

Reputation: 477

Creating a UITextField that creates a new line when needed

I was wondering how I could create a UITextField that would create a new line when the text reaches it's edge.

Here how I am creating the text view:

UITextField *textField = [[UITextField alloc] init];
textField.frame = CGRectMake(0, 194, 320, 568);
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
textField.backgroundColor = [UIColor whiteColor];
UIView *textPaddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 7, 20)];
textField.leftView = textPaddingView;
textField.leftViewMode = UITextFieldViewModeAlways;
[self.view addSubview:textField];

Upvotes: 1

Views: 82

Answers (1)

Mick MacCallum
Mick MacCallum

Reputation: 130222

No, you shouldn't do that. UITextField is only designed to have one line of text. The control that you should be using is UITextView, which supports the behavior you've described natively.

Upvotes: 3

Related Questions