[英]How to change the UiSearchbar height ,width , color and Uitextfield Height in UISearchBar in iphone?
[英]How to change cursor color in iphone's UISearchBar?
是否可以更改UISearchBar
中光標的顏色?
你實際上可以做的是:
[[UITextField appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:YOUR_COLOR_HERE];
如果您想要搜索欄本身的不同色調。
我創建了自己的SearchController
它擴展了UISearchController
並使用以下代碼為光標和取消按鈕使用不同的顏色
self.searchBar.barTintColor = UIColor.greyColor()
self.searchBar.tintColor = UIColor.greyColor()
UIBarButtonItem.appearance().tintColor = UIColor.whiteColor()
對於 SWIFT 5
self.searchBar.barTintColor = UIColor.gray
self.searchBar.tintColor = UIColor.gray
UIBarButtonItem.appearance().tintColor = UIColor.white
UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).tintColor = .lightGray
這會將光標調整為UIColor.lightGray
而不更改取消按鈕的顏色。
不幸的是沒有。 我還想在 UISearchBar 中使用自定義字體,但這也不可能。
盡管可能會以某種方式覆蓋整個 UISearchBar 類,但 Apple 不會接受任何更改其類的應用程序。 如果確實有必要,那么您可以創建自己的搜索欄。 不過,對於光標顏色似乎有很多工作。
這在 iOS 7 中是可能的。只需設置 UISearchBar 的色調顏色。 因此,例如,在您的應用委托中:
[[UISearchBar appearance] setTintColor:[UIColor redColor]];
據我所知,這只會影響光標顏色。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.