我现在正在为此苦苦挣扎。到处搜索,但提供的解决方案只适用于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