[英]Change Keyboard Color in UISearchBar with apperance
當用戶點擊搜索文本字段時,我想將鍵盤的顏色更改為黑色。
我試圖用UITextField *textField = [UITextField appearance]; [textField setKeyboardAppearance:UIKeyboardAppearanceAlert];
來實現它UITextField *textField = [UITextField appearance]; [textField setKeyboardAppearance:UIKeyboardAppearanceAlert];
UITextField *textField = [UITextField appearance]; [textField setKeyboardAppearance:UIKeyboardAppearanceAlert];
但是我的構建失敗並顯示此消息
由於未捕獲的異常“ NSInvalidArgumentException”而終止應用程序,原因:“-[[UISearchBarTextField _UIAppearance_setKeyboardAppearance:]:無法識別的選擇器已發送到實例0x8485260”
你能幫我嗎? 非常感謝
使用此代碼...
for(UIView *searchTextfield in yourSearchBar.subviews)
{
if([searchTextfield isKindOfClass: [UITextField class]]){
[(UITextField *)searchTextfield setKeyboardAppearance: UIKeyboardAppearanceAlert];
}
}
就像我的另一個答案一樣,其中我替換了按鈕Image see..uisearchbar的取消按鈕圖像
支持Paras Joshi的答案,以及iOS7 / 8的更新。 現在,UIView包裹在另一層中,因此您需要再次進行迭代。
for(UIView *searchTextfield in self.searchBar.subviews)
{
for(UIView *searchTextfield2 in searchTextfield.subviews) {
if([searchTextfield2 isKindOfClass: [UITextField class]]){
[(UITextField *)searchTextfield2 setKeyboardAppearance: UIKeyboardAppearanceDark];
}
}
}
標准免責聲明。 蘋果公司對此表示“正式”反對,但是由於您只是使用公共API遍歷UIViews,因此“在技術上”可以。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.