有没有任何想法或代码示例如何更改UISearchBar的占位符文本的文本颜色?
我想在新的导航栏中放置一个搜索栏,其中包含新的iOS 11大标题.但是,搜索栏的颜色会自动由iOS应用,我无法更改它.
if #available(iOS 11.0, *) {
let sc = UISearchController(searchResultsController: nil)
navigationItem.searchController = sc
navigationItem.hidesSearchBarWhenScrolling = false
}
Run Code Online (Sandbox Code Playgroud)
搜索栏是深蓝色背景,但我只想将其更改为白色.
设置背景颜色会导致:
navigationItem.searchController?.searchBar.backgroundColor = UIColor.white
Run Code Online (Sandbox Code Playgroud)
我也试过setScopeBarButtonBackgroundImage并setBackgroundImage在搜索栏上但是一切看起来都很奇怪.
此外,当我通过点击搜索栏触发搜索时,它会切换到右侧有取消按钮的模式.("Abbrechen"德文)
并且"Abbrechen"文本颜色也无法更改.(需要它也是白色的)
任何帮助表示赞赏.
编辑:根据要求,这里是导航栏样式的代码:
self.navigationBar.tintColor = UIColor.myWhite
self.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.myWhite, NSAttributedStringKey.font: UIFont.myNavigationBarTitle()]
self.navigationBar.barTintColor = UIColor.myTint
if #available(iOS 11.0, *) {
self.navigationBar.prefersLargeTitles = true
self.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.myWhite, NSAttributedStringKey.font: UIFont.myNavigationBarLargeTitle()]
}
Run Code Online (Sandbox Code Playgroud)
目前的结果:我使用Krunals的想法来设置搜索栏背景的颜色,但圆角丢失了.重新设置圆角后,搜索栏的动画似乎被打破.
所以仍然没有令人满意的解 似乎嵌入到iOS 11导航栏中的搜索栏无法自定义.同时,仅仅改变占位符文本的颜色就足够了,但即使这样也不可能.(我尝试过StackOverflow的多种方法 - 不起作用)