Search code examples
iphoneuitextview

Two blank space in UITextView automatically inserts a . (fullstop) after text in iPhone


I have a UITextView where I am inserting comma separated values. but when ever I insert any text and gives two or more space after it. It automatically appends the FULL STOP after last text.

Is it due to Phone setting? Even if yes. How can we prevent it?

EDIT To reproduce it.. Enter any word in UITextView and then try to apply two spaces. It will automatically add fullstop at the end of hte word :)


Solution

  • - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    {
    //Check for double space
    return !(range.location > 0 &&
             [text length] > 0 &&
             [[NSCharacterSet whitespaceCharacterSet] characterIsMember:[text characterAtIndex:0]] &&
             [[NSCharacterSet whitespaceCharacterSet] characterIsMember:[[textView text] characterAtIndex:range.location - 1]]);
    
    }
    

    Above code will limit user to enter more than one blank space.