我有一个只应该包含表情符号字符的文本字段。是否可以将用户的键盘限制为仅输入表情符号,即禁用其他键盘?
问问题
1721 次
2 回答
2
键盘类型可以在 Interface Builder 中设置,也可以使用本指南以编程方式设置:
typedef enum {
UIKeyboardTypeDefault, // Default type for the current input method.
UIKeyboardTypeASCIICapable, // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
UIKeyboardTypeNumbersAndPunctuation, // Numbers and assorted punctuation.
UIKeyboardTypeURL, // A type optimized for URL entry (shows . / .com prominently).
UIKeyboardTypeNumberPad, // A number pad (0-9). Suitable for PIN entry.
UIKeyboardTypePhonePad, // A phone pad (1-9, *, 0, #, with letters under the numbers).
UIKeyboardTypeNamePhonePad, // A type optimized for entering a person's name or phone number.
UIKeyboardTypeEmailAddress, // A type optimized for multiple email address entry (shows space @ . prominently).
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated
} UIKeyboardType;
表情符号键盘设置为单独的语言键盘,因此无法以编程方式设置。它由用户在设置应用程序中设置。
我想,即使它很麻烦,您也可以提醒您的用户或在您的应用程序中有一个帮助文件,说明要获得您的应用程序的最佳体验,他们需要启用它。
另请注意,我相信 Apple 现在拒绝创建自己的自定义表情符号键盘的应用程序,因为它现在是主操作系统的一部分。
于 2012-12-22T22:20:55.867 回答
1
目前正在开发一个要求与您相同的项目,并尝试搜索解决方案但没有找到,我编写了一个对我来说工作正常的代码。希望它也适合你。我知道为时已晚,但将来会帮助你。
我的解决方案是
#pragma mark validate emoji's
-(void)validateEmoji
{
BOOL lowerCaseLetter=0,upperCaseLetter= 0,digit=0,specialCharacter=0;
for (int i = 0; i < [emojiTextField.text length]; i++)
{
unichar c = [emojiTextField.text characterAtIndex:i];
if(!lowerCaseLetter)
{
lowerCaseLetter = [[NSCharacterSet lowercaseLetterCharacterSet] characterIsMember:c];
}
if(!upperCaseLetter)
{
upperCaseLetter = [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:c];
}
if(!digit)
{
digit = [[NSCharacterSet decimalDigitCharacterSet] characterIsMember:c];
}
if(!specialCharacter)
{
specialCharacter = [[NSCharacterSet symbolCharacterSet] characterIsMember:c];
}
}
if(lowerCaseLetter || upperCaseLetter || digit || specialCharacter)
{
// if textfield contains special characters,lowercase,uppercase,numeric digits
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Please select only emoji's from Keyboard"
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
emojiTextField.text=@"";
[emojiTextField becomeFirstResponder];
emojiTextFieldFlag = false;
}
else
{
emojiTextFieldFlag = true;
// emoji is selected do whatever you want.
}
}
#pragma mark TextField delegate methods
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ([textField isEqual:emojiTextField])
{
[emojiTextField resignFirstResponder];
NSLog(@"%@",emojiTextField.text);
// make it blank for next click when comes back
appdelegate.appdelegateEmojiTextFieldClicked =@"";
if (emojiTextFieldFlag)
{
[self saveEmojiJsonParsing];
}
else
{
[emojiTextField becomeFirstResponder];
}
}
return YES;
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
if ([textField isEqual:emojiTextField])
{
[self validateEmoji];
}
}
于 2015-04-28T09:08:11.873 回答