Remove the 1px border under UISearchBar

前端 未结 4 1320
长情又很酷
长情又很酷 2020-12-25 11:29

\"UISearchBar

I\'m having trouble removing that 1px border directly under the UISearchBar vi

相关标签:
4条回答
  • 2020-12-25 11:53
    [searchBar setBackgroundImage:[UIImage new]];
    
    0 讨论(0)
  • 2020-12-25 12:04

    Nevermind, I just did:

    searchBar.layer.borderWidth = 1;
    searchBar.layer.borderColor = [[UIColor whiteColor] CGColor];
    

    and it works!

    0 讨论(0)
  • 2020-12-25 12:13

    For Swift version, tested on iOS9:

    searchBar.backgroundImage = UIImage() 
    

    It would show like this:

    no-border-result

    0 讨论(0)
  • 2020-12-25 12:18

    In order to overcome this in Xamarin Forms, you'll need to create a CustomRenderer to the SearchBar class. Like this:

    using System;
    using Xamarin.Forms.Platform.iOS;
    using Xamarin.Forms;
    using MyProject.iOS;
    
    [assembly: ExportRenderer(typeof(SearchBar), typeof(CustomSearchBarRenderer))]
    namespace MyProject.iOS
    {
        public class CustomSearchBarRenderer:SearchBarRenderer
        {
            protected override void OnElementChanged (ElementChangedEventArgs<Xamarin.Forms.SearchBar> e)
            {
                base.OnElementChanged (e);
                if (this.Control == null) return;
    
                this.Control.BackgroundImage = new UIKit.UIImage ();
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题