UITextView UITextField

Target: Making content could type multiple-line.

enter image description here

UITextField is specifically one-line only.

Your Google search is correct, you need to use UITextView instead of UITextField for display and editing of multiline text.

In Interface Builder add a UITextView where you want it and select the “editable” box. It will be multiline by default.

How to detect user input character in UITextView

How to detect user input character in UITextView?

For example:(in UITextView NOT UITextField)

when user input letter “a”, trigger an event. when user input “do it”, trigger another event. or input “http://www.stackoverflow.com” trigger an event.


why don’t you try UITextFieldDelegate methods for that. – Leena Mar 21 ’12 at 5:48
– (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text it will fire for every charter press in textView – Narayana Mar 21 ’12 at 5:49
@Narayana you are the first correct. Next time you can put the answer to “Answer field”. Then I can tick you~ Thanks! – Jason Zhao Mar 22 ’12 at 5:53


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 
    NSString* parameterStr=@"";
    parameterStr=[[textField text] stringByAppendingString:string];    if([parameterStr isEqualToString:@"do it"] || [parameterStr isEqualToString:@"http://www.stackoverflow.com"] || [parameterStr isEqualToString:@"a"])
        return YES;
        return NO;
Thanks, but I changed your code, removed else return NO; – Jason Zhao Mar 22 ’12 at 5:52
Thats okay!! It was just a pattern, it would be changed as per your purpose of usage. – Kuldeep Mar 22 ’12 at 5:57
-1; the question explicitly asked for detecting content changes on a UITextView and not aUITextField. This is wrong and I don’t know why the question asker accepted it. The analagous method inUITextViewDelegate is, as mentioned in other answers, - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text (and both may be inappropriate for the asker’s use case; see stackoverflow.com/questions/7010547/…). – Mark Amery Jul 25 at 11:53


This delegate will be called whenever a user presses key

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    if([[textView.text stringByAppendingString:text] isEqualToString:"a"])
      //trigger 'a' operation
    else if([[textView.text stringByAppendingString:text] isEqualToString:"do it"])
      //trigger do it operation
    //Same conditions go on

How to style UITextview to like Rounded Rect text field?

//first, you
#import <QuartzCore/QuartzCore.h>


//Here I add a UITextView in code, it will work if it's added in IB too
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(50, 220, 200, 100)];

//To make the border look very close to a UITextField
[textView.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];
[textView.layer setBorderWidth:2.0];

//The rounded corner part, where you specify your view's corner radius:
textView.layer.cornerRadius = 5;
textView.clipsToBounds = YES;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s