修改UISearchBar背景颜色(内外框)

这里写图片描述

    self.noteSearchResultVC = [[NoteSearchResultViewController alloc]init];
    self.noteSearchResultVC.mainSearchController = self;
    self.noteSearchResultVC.noteSearchResultDelegate = self;
    self.searchVC = [[UISearchController alloc]initWithSearchResultsController:self.noteSearchResultVC];
    self.searchVC.searchBar.placeholder = @"搜索记事";

    //改变搜索框外部框的颜色(需要隐藏background才能显示背景色)
    self.searchVC.searchBar.backgroundImage = [[UIImage alloc]init];
    [self.searchVC.searchBar sizeToFit];
    //用textfiled代替搜索框
    UITextField *searchField=[self.searchVC.searchBar valueForKey:@"_searchField"];
    searchField.backgroundColor = UIColorFromRGB(227, 227, 227);
    //placeholderLabel.textColor的颜色
    [searchField setValue:UIColorFromRGB(122, 122, 122) forKeyPath:@"_placeholderLabel.textColor"];
    self.searchVC.searchBar.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.searchVC.searchBar.layer.borderWidth = 0.5;

    self.searchVC.hidesNavigationBarDuringPresentation = YES;
    self.searchVC.searchResultsUpdater = self;
    self.definesPresentationContext = YES;
    self.searchVC.searchBar.delegate = self;
展开阅读全文

没有更多推荐了,返回首页