0

I have a UISearchBar whose bartintcolor i have changed and have cancel enabled. This is added as a subview of a UIVew. whenever make search bar visible, it shows a black line below it which never goes away.

Am i missing something about UISearchbar appearence or its background view.

    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];

it gives me like this

Black line color just below

if i change background to native one, i get displaced content. // _searchBar.barTintColor = [Utilities colorWithHexString:@"3a7ebc"];

enter image description here

I just dont want the black line below the searchbar.

Updated: using _searchBar.searchBarStyle=UISearchBarStyleMinimal; _searchBar.barStyle=UIBarStyleDefault;

result in thisenter image description here

So finally everything done

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

1 Answers1

0

Put my code in viewdidload or viewwillappear method.

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

I would also consider, "I hope this will help you", as this is the strongest, and hopes that the thing will most definitely, certainly help.

If you like my Answer so accept and upvote my answer

Rohit suvagiya
  • 1,005
  • 2
  • 12
  • 40