Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

change navigation bar Search placeholder text color

joaopalmajoaopalma Member ✭✭
edited July 2018 in Xamarin.iOS

I'm having trouble to change the text color of the placeholder

textFieldInsideSearchBar.AttributedPlaceholder = new NSAttributedString("Search", foregroundColor: UIColor.White);

I'm able to change any other attributes except this one.

Its a bug or I'm doing it wrong ?


  • ColeXColeX Member, Xamarin Team Xamurai
    edited July 2018

    I tried your code , it works fine on my side .

    How do you access the textField inside SearchBar ? Can you attach your code ?

    This is my code :

        UITextField textfield = null;
        foreach (UIView subView in searchBar.Subviews)
            foreach (UIView ndLeveSubView in subView.Subviews)
                if (ndLeveSubView is UITextField)
                    textfield = ndLeveSubView as UITextField;
        textfield.AttributedPlaceholder = new NSAttributedString("Search", foregroundColor: UIColor.Red);
  • joaopalmajoaopalma Member ✭✭

    Very strange to work for you, I read somewhere its not possible to change the foregroundcolor

  • To anyone else who stumbles on this. You can change the magnifying glass, placeholder, & cancel button image as below in iOS custom renderer.

    `protected override void OnElementChanged(ElementChangedEventArgs e)
    if (Control != null)
    Control.SearchBarStyle = UISearchBarStyle.Minimal;
    var searchbar = (UISearchBar)Control;
    if (e.NewElement != null)

                    var searchTextField = searchbar.ValueForKey((Foundation.NSString)"_searchField") as UITextField;
                    var glassview = (searchTextField.LeftView) as UIImageView;
                    glassview.Image = glassview.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
                    glassview.TintColor = UIColor.White;
                    //x button
                    var clearButton = searchTextField.ValueForKey((Foundation.NSString)"_clearButton") as UIButton;
                    if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
                        clearButton.SetImage(UIImage.FromBundle("my_white_clear_button"), UIControlState.Normal);
                        clearButton.TintColor = UIColor.Red;
                    else {
                        clearButton.SetImage(clearButton.ImageView.Image, UIControlState.Normal);
                        clearButton.TintColor = UIColor.Red;
                    var searchButton = searchTextField.ValueForKey((Foundation.NSString)"_placeholderLabel") as UILabel;
                    searchButton.TextColor = UIColor.White;
Sign In or Register to comment.