Recent searches


No recent searches

How to change the color of the search bar placeholder in the iOS SDK

Answered


Posted Jul 12, 2021

I would like to know how to change the color of the search bar placeholder in the iOS SDK.

What should I write by creating help_center_article_style.css?

Thank you.

 


0

7

7 comments

image avatar

Eric Nelson

Zendesk Developer Advocacy

Hey Asa,

This will actually be set in your appDelegate file. You can accomplish this with the UIkit specifically the UISearchBar. I've included an example on how to accomplish below:

        UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
        UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).attributedPlaceholder = NSAttributedString(string: "Search...", attributes: [NSAttributedString.Key.foregroundColor: UIColor.lightGray]

Hope this helps!

Have a wonderful day!

Eric Nelson | Manager - Developer Advocacy

1


Hi, Eric

Thank you for your adcive!

I try it, so I have another problem.

I can not show anything first, but can show after editing.

Please tell me if you know anything.

Thank you.

- First

- Editing

0


image avatar

Eric Nelson

Zendesk Developer Advocacy

Hey Asa,

In that case you'd just want to use this line instead of the two I provided before:

UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).attributedPlaceholder = NSAttributedString(string: "Search...", attributes: [NSAttributedString.Key.foregroundColor: UIColor.lightGray]

Let me know if that does the trick!

Have a wonderful day!

Eric Nelson | Manager - Developer Advocacy

0


Hey Eric Nelson!

I have the same problem you mentioned earlier and I am trying to fix it according to your way, but the problem remains unresolved.

Could you please help me? 

0


image avatar

Eric Nelson

Zendesk Developer Advocacy

Hey Nikita,

Can you provide the corresponding code snippets so that I can take a look?

Thanks!

0


Hey Eric Nelson, yeah, shure, there is my code on this screenshot. 

Thank you a lot. 

0


image avatar

Eric Nelson

Zendesk Developer Advocacy

Hey Nikita,

Everything looks good code-wise, what does the UI look like when using this code? 

0


Post is closed for comments.

Didn't find what you're looking for?

New post