Renan Renan - 5 months ago 14
iOS Question

Change text color of search bar ios

Is it possible to change the text color of the search bar? I don't seem to have access to the UISearchBarTextField class...

Answer

firstly, you find the subview in UISearchBar, then find the UITextField in sub View then change color

Try this code:-

 for(UIView *subView in searchBar.subviews){
            if([subView isKindOfClass:UITextField.class]){
                [(UITextField*)subView setTextColor:[UIColor blueColor]];
            }
        }

for Ios 5 +

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor blueColor]];
Comments