How to make UITextField text multiple lines
In my app, I have a textbox that the user can fill. Most times, t开发者_开发问答his 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?
Just Go With UITextView instead of UITextField.
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.
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 !
精彩评论