UISearchBar的底线

时间:2019-01-04 06:44:45

标签: ios swift xamarin xamarin.ios

如何删除UITableViewController中的UISearchBar底线?

也可以应用快速解决方案。

enter image description here

这是我的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;

对于 AppDeletage.cs

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

我尝试了几乎所有在Internet上找到的解决方案。

不要使用下一个解决方案:

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;

1 个答案:

答案 0 :(得分:1)

这是解决方法:

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