iOS searchbar textfield placeholder color

Posted Ficow Shen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS searchbar textfield placeholder color相关的知识,希望对你有一定的参考价值。

 

 

// Get the instance of the UITextField of the search bar

UITextField *searchField = [searchBar valueForKey:@"_searchField"];

// Change search bar text color
searchField.textColor = [UIColor redColor];

// Change the search bar placeholder text color
[searchField setValue:[UIColor blueColor] forKeyPath:@"_placeholderLabel.textColor"];

//Change search bar icon if needed
[self.searchBar setImage:[UIImage imageNamed:@"searchIcon"]
   forSearchBarIcon:UISearchBarIconSearch
              state:UIControlStateNormal];



[self.searchBar setValue:[UIColor whatever] forKeyPath:@"_searchField._placeholderLabel.textColor"];

  

以上是关于iOS searchbar textfield placeholder color的主要内容,如果未能解决你的问题,请参考以下文章

SwiftUI:自定义SearchBar

10-3基于TextField实现顶部SearchBar-2

如何使用 SearchBar 从服务器获取数据

带有 SearchBar 的 iOS 11 导航栏大小

显示视图时 searchBar 不可见 - ios 11

@State 错误我位于导航栏的 TextField - SwiftUI