2013-01-31 27 views
4

我目前正试图设置全局的键盘样式,但我的方法不起作用。 我尝试了用UIAppearance,并把此行的代码的AppDelegate里面:如何为整个应用程序设置UIKeyboard风格?

[[UITextField appearance] setKeyboardAppearance:UIKeyboardAppearanceAlert]; 

但我在控制台上得到如下:

[UISearchBarTextField _UIAppearance_setKeyboardAppearance:]: unrecognized selector sent to instance 0xa1897e0 

任何想法如何解决这个问题?

+0

您是否找到解决方案? – BlueVoodoo

回答

2

UIAppearance只适用于使用宏UI_APPEARANCE_SELECTOR明确标记的方法兼容,不幸的是keyboardAppearance不是其中之一。

最好的方式来得到你想要的是继承UITextField,并在子类的initinitWithFrame:方法来设置keyboardAppearance = UIKeyboardAppearanceAlert;。然后专门使用您的班级,无论您在应用中使用UITextField

7

iOS7扩展了UIAppearance协议的UITextFields,你可以在UITextField上设置现在的键盘外观。

[UITextField appearance].keyboardAppearance = UIKeyboardAppearanceDark; 

但是,UITextView不支持它。对于这门课程,我会选择jszumski的解决方案

+0

'UITextView'适用于iOS8。 – yuhua

+0

我最近尝试过,它不起作用(iOS 8.2)。至少,结合表格视图 – tubtub

+0

是的!它可能会导致崩溃,但你仍然可以直接设置为textview'textView.keyboardAppearance = UIKeyboardAppearanceDark;' – yuhua

相关问题