我現在正在爲此苦苦掙扎。到處搜索,但提供的解決方案只適用於Objective-C。其中包括在更改UISearchBar的textField背景
UITextField *txt = [_searchBar valueForKey:@"_searchField"];
雖然有些人可能會說,這是受保護的API和蘋果公司可能會拒絕這樣的代碼的應用程序。
所以,現在我已經嘗試了很多方法來解決這個問題,它根本就不工作。 我的代碼是這樣的:
searchBar = UISearchBar(frame: CGRectMake(0, 0, 320.0, 30.0))
searchBar.autoresizingMask = UIViewAutoresizing.FlexibleWidth
searchBar.searchBarStyle = UISearchBarStyle.Minimal
searchBar.layer.cornerRadius = 15
searchBar.delegate = self
searchBar.backgroundColor = UIColor.whiteColor()
if floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1{
// Load resources for iOS 6.1 or earlier
searchBar.placeholder = "Search";
} else {
// The following "hack" (if we can call that) breaks the UI for different size devices.
// Load resources for iOS 7 or later
searchBar.placeholder = "Search ";
}
這讓我奇怪的結果:
而我想要的只是該的UISearchBar裏面的文本框有一個白色的背景和搜索欄本身具有的cornerRadius ,說,15.
我該怎麼做?
在此先感謝
的UITextField * searchField = [SearchBar valueForKey:@「_ searchField」]; searchField.textColor = [UIColor whiteColor]; 我已經在我的應用程序和應用程序中使用此代碼,它已經在App Store中可用。 – Bhoomi 2015-04-04 05:42:55