Iphone UITextView的键盘类型

Iphone UITextView的键盘类型,iphone,objective-c,ios,uitextview,uikeyboardtype,Iphone,Objective C,Ios,Uitextview,Uikeyboardtype,我想知道如何获取uitextview的键盘类型。 我可以通过使用textfield.keyboardtype获得uitextfield的键盘类型,但它似乎不适用于uitextview。 请帮我解决这个问题 提前谢谢。试试这个 UITextView *txvw = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 24, 20)]; txvw.keyboardType =UIKeyboardTypeURL; 还有其他键盘类型 UIKeyboar

我想知道如何获取uitextview的键盘类型。 我可以通过使用textfield.keyboardtype获得uitextfield的键盘类型,但它似乎不适用于uitextview。 请帮我解决这个问题

提前谢谢。

试试这个

UITextView *txvw = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 24, 20)];
txvw.keyboardType =UIKeyboardTypeURL;
还有其他键盘类型

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).

如果您只是阅读UITextView类参考,它在键盘上有一个完整的部分,其中包含以下文本:

可以使用UITRAITS协议提供的属性自定义键盘本身的外观。文本视图对象实现此协议并支持其定义的属性。您可以使用这些属性指定键盘的类型(ASCII、数字、URL、电子邮件和其他)显示。您还可以配置键盘的基本文本输入行为,例如它是否支持文本的自动大小写和更正。“

因此,这意味着UITextView采用uitextraits协议,这意味着它响应每一条所需的消息。要重写方法,您需要将UITextView子类化,然后将方法添加到子类以返回不同的键盘类型等


对于属性,您可以按照其他响应者的建议设置属性。

此问题将帮助您:

您可以使用与UITextField相同的方法获取UITextView的键盘类型

 UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(0,0,320,30)];
 [self.view addSubview:textView];
 UIKeyboardType type = textView.keyboardType;
 [textView release];

调用textview.keyboardType返回什么?