如何更改搜索控制器中的 uitextfield 颜色? [英] how to change uitextfield color in searchcontroller?

查看:17
本文介绍了如何更改搜索控制器中的 uitextfield 颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在导航栏中嵌入了 SearchController .如何将 UITextField 颜色更改为将搜索字符串保存为白色的颜色.?

i have embedded SearchController in navigation bar . How to Change UITextField Color The one which Holds search String To White .?

推荐答案

这将帮助您实现您想要的.只需在此代码中应用您的颜色组合并查看.

This will help you to achieve, what you want. Just apply your color combination in this code and see.

if #available(iOS 11.0, *) {
            let sc = UISearchController(searchResultsController: nil)
            sc.delegate = self
            let scb = sc.searchBar
            scb.tintColor = UIColor.white
            scb.barTintColor = UIColor.white


            if let textfield = scb.value(forKey: "searchField") as? UITextField {
                //textfield.textColor = // Set text color
                if let backgroundview = textfield.subviews.first {

                    // Background color
                    backgroundview.backgroundColor = UIColor.white

                    // Rounded corner
                    backgroundview.layer.cornerRadius = 10;
                    backgroundview.clipsToBounds = true;

                }
            }

            if let navigationbar = self.navigationController?.navigationBar {
                navigationbar.barTintColor = UIColor.blue
            }
            navigationItem.searchController = sc
            navigationItem.hidesSearchBarWhenScrolling = false

}

结果:

这篇关于如何更改搜索控制器中的 uitextfield 颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆