键盘类型用于UITextView

时间:2012-07-19 13:04:56

标签: iphone objective-c ios uitextview uikeyboardtype

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

提前致谢。

4 个答案:

答案 0 :(得分:8)

试试这个

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

答案 1 :(得分:1)

您可以使用与UITextField相同的方式获取UITextView的keyboardType。

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

答案 2 :(得分:0)

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

“可以使用UITextInputTraits协议提供的属性自定义键盘本身的外观。文本视图对象实现此协议并支持它定义的属性。您可以使用这些属性指定键盘类型(ASCII,Numbers您可以配置键盘的基本文本输入行为,例如它是否支持自动大写和文本更正。“

这意味着UITextView采用UITextInputTraits协议,这意味着它会响应每条所需的消息。要覆盖方法,您需要继承UITextView,然后将方法添加到子类以返回不同的键盘类型等。

对于属性,您可以像其他响应者建议的那样设置属性。

答案 3 :(得分:0)