UISearchBar - UISearchBar的不同tableview背景

时间:2016-02-05 10:13:17

标签: ios objective-c uitableview uisearchbar

当我搜索 UISearchBar 时,我的正常tableView已设置为

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 

{   

CustomCell *cell=(CustomCell *)[FieldTableView dequeueReusableCellWithIdentifier:@"Cell"];

        //set cell background color cleare color
         cell.backgroundColor=[UIColor clearColor];

if (isSearching) {
    cell.AddPFFieldLable.text = [filteredContentList objectAtIndex:indexPath.row];    
} else {
    cell.AddPFFieldLable.text=[[fieldArray objectAtIndex:indexPath.row]valueForKey:@"FName"];
}

My Normal TableView

但当我搜索任何内容时,它会显示如下

how to change its background color to clearcolor

如何将背景颜色更改为 clearColor

2 个答案:

答案 0 :(得分:1)

好的,我得到了我的查询答案

[self.searchDisplayController.searchResultsTableView setBackgroundColor:[UIColor clearColor]];

viewDidLoad中唯一缺少的东西。

答案 1 :(得分:0)

我在UISearchBar中使用了这段代码。根据您的要求使用

-(void)addSearchController {
    // No search results controller to display the search results in the current view

    [[UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:CODE_2_COLOR];

    self.searchDisplayController.searchBar.placeholder = @"Search your connection list";


    UITextField *txfSearchField = [self.searchDisplayController.searchBar valueForKey:@"_searchField"];
    txfSearchField.backgroundColor = CODE_6_COLOR;
    self.searchDisplayController.searchBar.barTintColor=CODE_6_COLOR;
    CGRect rect = self.searchDisplayController.searchBar.frame;
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, rect.size.height-2,rect.size.width, 2)];
    lineView.backgroundColor = CODE_6_COLOR;
    [self.searchDisplayController.searchBar addSubview:lineView];
    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{
                                                                                                 NSFontAttributeName: [FontManager getRobotoMediumFontWithSize:14],
                                                                                                 }];

    self.tableView.tableHeaderView = self.searchDisplayController.searchBar;

}