How to move search icon of search bar at right hand side in iOS

Mahesh_MMahesh_M Member ✭✭

We can replace search icon to right side of searchbar(IN ANDRIOD) by rendering as shown below:

             var searchView = base.Control as SearchView;
            int searchIconId = Context.Resources.GetIdentifier("android:id/search_mag_icon", null, null);
            ImageView searchViewIcon = (ImageView)searchView.FindViewById<ImageView>(searchIconId);
            ViewGroup searchViewLayout = (ViewGroup)searchViewIcon.Parent;
            searchViewIcon.SetAdjustViewBounds(true);
            searchViewLayout.RemoveView(searchViewIcon);
            searchViewLayout.AddView(searchViewIcon);
            this.Control.Background = this.Resources.GetDrawable(Resource.Drawable.RectangularSearchBar);

But how can we acheive this in iOS??

Answers

  • I need this too, did you find a solution?

  • AbdulbashaAbdulbasha USMember ✭✭

    This is actual image:

    This is My requirements :

    here is the solution :

        protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
        {       
               base.OnElementChanged(e);
    
                var searchbar = (UISearchBar)Control;
                if (e.NewElement != null)
                {
                    searchbar.Layer.CornerRadius = 5;
                    searchbar.Layer.BorderWidth = 1;
                    searchbar.Layer.BorderColor = UIColor.FromRGB(112, 112, 112).CGColor;
    
                    var searchTextField = searchbar.ValueForKey((Foundation.NSString)"_searchField") as UITextField;
                    var clearButton = searchTextField.ValueForKey((Foundation.NSString)"_clearButton") as UIButton;
                    clearButton.SetImage(UIImage.FromBundle("SearchCloseIcon.png"), UIControlState.Normal);
                }          
        }
    
Sign In or Register to comment.