改变UISearchBar输入框的颜色, 修改UISearchBar默认颜色

2019-05-30 09:44:00

改变UISearchBar输入框的颜色

    UISearchBar *search = [[UISearchBar alloc] init];
    if (_searchStr) {
        search.text = _searchStr;
    }
    [search setPlaceholder:@"输入人员名称"];
    [search setBackgroundImage:[UIImage new]];
    search.barStyle = UISearchBarStyleMinimal;
    search.delegate = self;
    UITextField *searchField=[search valueForKey:@"searchField"];
    searchField.backgroundColor = [UIColor colorWithRed:220.0/255.0 green:220.0/255.0 blue:220.0/255.0 alpha:0.7];
    [_searchViews addSubview:search];

原文:

我们其实都知道UISearchBar是UITextFiled和UISegmentedControl的组合和扩展,我们如果需要修改我们搜索栏里面的文本框的颜色,我们应该怎么修改呢,我们要修改搜索栏的placeholder的颜色又应该怎么修改呢?还有有一些普遍的属性具体看代码。

searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];
    searchBar.placeholder=@"大家都在搜";//设置搜索框中带有的字体,一点击搜索框就会消失
    searchBar.tintColor=[UIColor redColor];//设置光标的颜色
 //searchBar.tintColor=[UIColor redColor];设置光标的颜色
    UITextField *searchField=[searchBar valueForKey:@"searchField"];
    searchField.backgroundColor = [UIColor colorWithRed:220.0/255.0 green:220.0/255.0 blue:220.0/255.0 alpha:0.3];//以此来设置搜索框中的颜色
     //[searchField setValue:[UIColor blueColor]forKeyPath:@"placeholderLabel.textColor"];改变搜索框中的placeholder的颜色

--------------------- 
作者:MooAiFighting 
来源:CSDN 
原文:https://blog.csdn.net/zcmuczx/article/details/74925161 
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »