Enrico Susatyo
Enrico Susatyo

Reputation: 19790

How to make UITextField text multiple lines

In my app, I have a textbox that the user can fill. Most times, this will be quite a lenghty text, I'm using UITextField but this does not go to a new line when the user types over the iPhone screen. How do I make it go to the next line?

Upvotes: 3

Views: 22027

Answers (3)

Ahmad Kayyali
Ahmad Kayyali

Reputation: 8243

 Just Go With UITextView instead of UITextField.

Upvotes: 11

Hussain KMR Behestee
Hussain KMR Behestee

Reputation: 852

UITextField doesn't provide any option to make it multi-lined text box. So you have to go with UITextView.

In interface builder place an UITextView and connect with an IBOutlet. I am assuming that you know how to do that.

Suppose you connected this UITextView with an IBOutlet named address. So now write the following code on viewDidLoadmethod.

- (void)viewDidLoad
{
    [super viewDidLoad];

    address.layer.cornerRadius = 5;
    [address.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];

    [address.layer setBorderWidth:2.0];
    address.clipsToBounds = YES;
}

Now add this line at the beggening of the file to import QuarzCore library

#import <QuartzCore/QuartzCore.h>

Now your TextView will look like a TextFiled.

Hope it will work for you.

Upvotes: 5

Sacha
Sacha

Reputation: 127

I'm not sure , but maybe this could help you :
- Go to the interface builder
- On the text field attributes , change the border to your type
- Some border are made so you can change the size and all

Hope it helps !

Upvotes: 0

Related Questions