Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable return key in UITextView

I am trying to disable the return key found when typing in a UITextView. I want the text to have no page indents like found in a UITextField. This is the code I have so far:

- (BOOL)textView:(UITextView *)aTextView shouldChangeTextInRange:(NSRange)aRange replacementText:(NSString*)aText
{
if ([aTextView.text isEqualToString:@"\r\n"]) {
    return NO;
}

Any ideas?


1 Answers

Try to use like this..

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {

    if([text isEqualToString:@"\n"])
    {
        [textView resignFirstResponder];
        return NO;
    }

    return YES;
}
like image 95
Dharmbir Singh Avatar answered Sep 12 '25 21:09

Dharmbir Singh