iphone - 更改搜索栏中的键盘颜色和外观

标签 iphone ios objective-c cocoa-touch ios5

当用户点击搜索文本字段时,我想将键盘的颜色更改为黑色。

我试图通过以下方式实现它 UITextField *textField = [UITextField 外观]; [textField setKeyboardAppearance:UIKeyboardAppearanceAlert];

但是我的构建失败并显示此消息

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISearchBarTextField _UIAppearance_setKeyboardAppearance:]: unrecognized selector sent to instance 0x8485260'

请问你能帮我吗? 非常感谢

最佳答案

使用此代码...

    for(UIView *searchTextfield in yourSearchBar.subviews)
    {
        if([searchTextfield isKindOfClass: [UITextField class]]){
            [(UITextField *)searchTextfield setKeyboardAppearance: UIKeyboardAppearanceAlert];
        }
    }

它与我的另一个答案相同,其中我替换了按钮 Image see.. image-for-cancel-button-of-uisearchbar

关于iphone - 更改搜索栏中的键盘颜色和外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16275061/

相关文章:

ios - 在 Xcode 中查找编辑功能

iphone - 从具有多对多关系核心数据 iOS 的上下文中删除 nsmanagedobject

ios - apple watch通知后异步加载数据

ios - Spotify 搜索中的问题

iphone - 从自定义 UITableViewCell 获取 textField.text

iphone - 动态分配随机图像作为按钮的背景

iphone - 无法从 XIB 中的属性检查器将 UIWebView 背景颜色更改为 clearcolor

iphone - 应用程序转到后台时播放音频

iphone - UITextView 类似 iPhone 笔记应用程序

ios - 向图层添加 CAAnimation 时, "forKey"参数的用途是什么?