ios UI搜索栏在它下面显示一条永远不会消失的线

tag5nh1u  于 5个月前  发布在  iOS
关注(0)|答案(1)|浏览(98)

我有一个UISearchBar的bartintcolor我已经改变,并已取消启用。这是作为一个UIVew的子视图添加的。每当使搜索栏可见,它显示了一个黑色的线下,它永远不会消失。
我错过了一些关于UISearchbar外观或其背景视图。

dummyview=[[UIView alloc]initWithFrame:CGRectMake(10, 30,self.headerView.frame.size.width-20, 30)];
    [dummyview setBackgroundColor:[UIColor redColor]];
    [dummyview setClipsToBounds:TRUE];
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, dummyview.frame.size.width, dummyview.frame.size.height)];
    self.searchBar.delegate = (id)self;
    [self.searchBar setPlaceholder:@"Search"];

    self.searchBar.showsCancelButton = YES;
    _searchBar.barTintColor = [Utilities colorWithHexString:@"3a7ebc"];
    [[UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:[UIColor whiteColor]];

    _searchBar.delegate=self;
    [dummyview addSubview:_searchBar];

字符串
它给了我这样的感觉


的数据
如果我把背景改成原生的,我会得到替换的内容。// _searchBar.barTintColor = [Utilities colorWithHexString:@"3a7ebc"];



我只是不想在搜索栏下面的黑线。
更新:使用_searchBar.searchBarStyle=UISearchBarStyleMinimal; _searchBar.barStyle=UIBarStyleDefault;
结果为this

最后一切都结束了
_searchBar.searchBarStyle=UISearchBarStyleMinimal; _searchBar.barStyle=UIBarStyleDefault; UITextField *searchField=[_searchBar valueForKey:@"_searchField"]; if (searchField) { [searchField setTextColor:[UIColor whiteColor]]; }

dl5txlt9

dl5txlt91#

把我的代码放在viewdidload或viewwillappear方法中。

searchbar.barTintColor=[UIColor samebgcolor];
searchbar.layer.borderWidth = 1;
searchbar.layer.borderColor = [[UIColor samebgcolor] CGColor];

字符串

相关问题