How to make UITextField text multiple lines
Solution 1
Just Go With UITextView instead of UITextField.
Solution 2
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.
Enrico Susatyo
Current: Software Engineer (Contract) Previous: VP Engineering at Beaconmaker. Software Engineer at Vivant and Atlassian. Casual Academic at Macquarie University. Notable side projects: Simple Stat My Github and Bitbucket Other notable achievements: Opalapp was featured in Mashable, Lifehacker, and other Australian media. Did I help solve your StackOverflow question? Want to thank me? I'm always happy to read more books on my Kindle :) Want to hire me or just have a chat with me? Drop me a line. My email is right here on this page. No unsolicited advertising, please.
Updated on July 09, 2022Comments
-
Enrico Susatyo almost 2 years
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?