我想在搜索控制器中更改无结果的颜色。我可以改变搜索表背景颜色单独的indexcolor。
答案 0 :(得分:0)
尝试这样,
创建一个属性
@property (nonatomic, strong) UISearchController * searchController;
然后添加以下内容:
// When the user types in the search bar, this method gets called.
- (void)updateSearchResultsForSearchController:(UISearchController *)aSearchController {
//// .. do whatever your search results..
for (UIView *subview in ((UITableViewController *)self.searchController.searchResultsController).tableView.subviews) {
if ([subview isKindOfClass:[UILabel class]]) {
if ([((UILabel *)subview).text isEqualToString:@"No Results"]) {
((UILabel *)subview).textColor = [UIColor redColor];
}
}
}
}
编辑回答:
for (UIView *subview in self.searchDisplayController.searchResultsTableView.subviews) {
if ([subview isKindOfClass:[UILabel class]]) {
if ([((UILabel *)subview).text isEqualToString:@"No Results"]) {
((UILabel *)subview).textColor = [UIColor redColor];
}
}
}