我在较早的版本中使用它来在我的searchBar中获取文本字段...
UITextField *searchField = [self.navigationItem.searchController.searchBar valueForKey:@"_searchField"];
Run Code Online (Sandbox Code Playgroud)
在iOS11中,它仍然可以使用,我可以更改文本(字体,甚至colortcolor),但是我无法设置文本颜色,请教我。
UISearchController *mySearchController = [[UISearchController alloc] initWithSearchResultsController:nil];
mySearchController.searchResultsUpdater = self;
self.navigationItem.searchController = mySearchController;
Run Code Online (Sandbox Code Playgroud)
// mySearchController.hidesNavigationBarDuringPresentation = false; self.navigationItem.hidesSearchBarWhenScrolling = NO;
self.tableView.refreshControl = [[UIRefreshControl alloc] init];
[self.tableView.refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
self.navigationItem.title = @"xxxx";
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"reload" style:UIBarButtonItemStylePlain target:self action:@selector(refresh)];
self.navigationItem.rightBarButtonItem = item;
UITextField *txfSearchField = [self.navigationItem.searchController.searchBar valueForKey:@"_searchField"];
txfSearchField.tintColor=[UIColor blueColor];
//this code is no use
txfSearchField.textColor=[UIColor yellowColor];
txfSearchField.backgroundColor=[UIColor whiteColor];
UIView *backgroundview= [[txfSearchField subviews]firstObject ];
backgroundview.backgroundColor=[UIColor whiteColor];
backgroundview.layer.cornerRadius = 8; …Run Code Online (Sandbox Code Playgroud)