I have a UISearchBar as seen below. How can I change the text color for the cancel button?

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This question was asked a while ago, therefore I assume that the person who asked has already found a solution. But just in case some others happen to bump into the same problem. Here is my solution.
I have a UISearchBar with a cancel button that appears only when the textfield of the UISearchBar is tapped. The solution of overriding -(void)layoutSubviews in a subclass of UISearchBar was therefore not an option for me. Anyway I did a subclass of UISearchBar (CustomSearchBar) with a public method for setting the font and textColor of the cancel button. When I create the UISearchBar I make sure that the search bar’s textfield delegate is set to self and the class that creates the search bar, implements the UITextFieldDelegate protocol. When the user taps on the search bar’s textfield, its delegate is informed and calls the method of CustomSearchBar. The reason why I do it here, is because it’s the moment when the cancel button appears and therefore I know that it is on the view hierarchy and I can do its customization.
Here’s the code:
For creating the UISearchBar in MyRootViewController
UITextFieldDelegate in MyRootViewController (make sure that it implements the UITextFieldDelegate protocol)
And this is the public method in the UISearchBar’s subclass