Atlantis
Atlantis

Reputation: 775

UISearchBar bottom line

How can I remove UISearchBar bottom line in UITableViewController?

Swift solution also could be applied.

enter image description here

Here is my code for VC:

NavigationController.NavigationBar.PrefersLargeTitles = true;
NavigationController.NavigationItem.LargeTitleDisplayMode =  UINavigationItemLargeTitleDisplayMode.Automatic;
NavigationItem.HidesSearchBarWhenScrolling = false;
var searchController = new UISearchController(searchResultsController: null);
NavigationItem.SearchController = searchController;
NavigationItem.SearchController.DefinesPresentationContext = true;
NavigationItem.SearchController.DimsBackgroundDuringPresentation = false;

For AppDeletage.cs

UINavigationBar.Appearance.Translucent = false;
UINavigationBar.Appearance.ShadowImage = new UIImage();

I tried almost all solutions which I've found over the Internet.

Don't work next solutions:

UISearchBar.Appearance.BackgroundImage = null;
UISearchBar.Appearance.BackgroundColor= UIColor.Clear;

NavigationItem.SearchController.Layer.BorderWidth = 0
NavigationItem.SearchController.Layer.BorderColor = UIColor.White.CGColor

NavigationItem.SearchController.SearchBar.ClipsToBounds = true;

Upvotes: 0

Views: 311

Answers (1)

Atlantis
Atlantis

Reputation: 775

Here is solution:

public override void ViewWillLayoutSubviews()
{
    base.ViewWillLayoutSubviews();
    ((UIImageView) NavigationItem.SearchController.SearchBar.Superview?.Subviews.First().Subviews.First()).Bounds = CGRect.Null;
}

Upvotes: 2

Related Questions