我有一个 UITextView,我在其中插入逗号分隔值。但是当我插入任何文本并在其后留出两个或更多空间时。它会自动在最后一个文本后附加 FULL STOP。
是手机设置的原因吗?即使是。我们如何预防?
编辑要重现它.. 在 UITextView 中输入任何单词,然后尝试应用两个空格。它会自动在 hte word 末尾添加句号 :)
- (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]]);
}
Run Code Online (Sandbox Code Playgroud)
上面的代码将限制用户输入多个空格。
| 归档时间: |
|
| 查看次数: |
3854 次 |
| 最近记录: |