iPhone: Disable the “double-tap spacebar for .” shortcut?

前端 未结 8 1757
陌清茗
陌清茗 2020-11-28 15:29

By default, if you tap the spacebar twice on the iPhone or iPad, instead of getting \"  \" (two spaces), you get \". \" (a period followed by a space). Is the

8条回答
  •  再見小時候
    2020-11-28 15:43

    Put this in your delegate class:

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
     //Check for double space
     return !(range.location > 0 && 
              [string length] > 0 &&
              [[NSCharacterSet whitespaceCharacterSet] characterIsMember:[string characterAtIndex:0]] &&
              [[NSCharacterSet whitespaceCharacterSet] characterIsMember:[[textField text] characterAtIndex:range.location - 1]]);
    
    }
    

提交回复
热议问题