【问题标题】:I want to Change Color of 'No Results' in Searchdisplaycontroller我想在 Uisearchdisplaycontroller 中更改“无结果”的颜色
【发布时间】:2017-04-19 05:41:12
【问题描述】:

我想在搜索控制器中更改 No Results 的颜色。我可以更改搜索表背景颜色单独的 indexcolor。

【问题讨论】:

    标签: ios objective-c uicolor uisearchdisplaycontroller


    【解决方案1】:

    试试这样,

    创建一个属性

    @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];
                }
            }
        }
    

    【讨论】:

    • 您是如何实现 UISearchController 的?是这样的[[UISearchController alloc] initWithSearchResultsController:searchResultsController]吗?
    • 我像“self.searchDisplayController.searchResultsTableView”一样使用它
    • 更新了答案,请检查并告诉我
    • 不客气,如果你想支持我,请接受答案并投票:)
    猜你喜欢
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多