0

我有一个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;

导致这个在此处输入图像描述

所以最后一切都完成了

_searchBar.searchBarStyle=UISearchBarStyleMinimal; _searchBar.barStyle=UIBarStyleDefault; UITextField *searchField=[_searchBar valueForKey:@"_searchField"]; if (searchField) { [searchField setTextColor:[UIColor whiteColor]]; }

4

1 回答 1

0

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

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

我也会考虑,“我希望这会帮助你”,因为这是最强大的,并希望这件事最肯定,肯定会有所帮助。

如果您喜欢我的回答,请接受并支持我的回答

于 2015-11-17T12:09:18.637 回答