[英]Possible to change the text color within a search bar while it is displayed?
我試圖在搜索欄中以一種顏色顯示初始提示消息,然后在用戶開始輸入文本后立即刪除提示並更改用戶輸入的文本顏色。
我正在使用它來設置提示消息的初始顏色
UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).textColor = UIColor.lightGrayColor()
然后,當我收到通知時,用戶已開始輸入文本,我嘗試更改顏色
func searchBar(searchBar: UISearchBar, textDidChange searchText: String)
{
appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).textColor = UIColor.blackColor()
...
似乎只能在顯示搜索欄之前設置顏色,而不能在已經顯示之后設置。 有人知道任何解決方法嗎?
(正在通過UISearchController自動創建並顯示搜索欄)
使用UISearchBar
的占位符屬性設置初始提示消息。 默認情況下, UISearchBar
會將其顏色設置為70%灰色,完全獨立於用戶輸入文本的文本顏色。
var searchBar = UISearchBar()
// This message will be set to a gray color by default
// UISearchBar will automatically clear it once the user starts typing
searchBar.placeholder = "Enter a message here..."
// This text color will be applied to the text that the user types
searchBar.textColor = UIColor.blackColor()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.