how to change UISearchBar textfield background color and text color in ios8 how to change UISearchBar textfield background color and text color in ios8 objective-c objective-c

how to change UISearchBar textfield background color and text color in ios8


Try this:

UITextField *searchField = [self.searchBar valueForKey:@"searchField"];// To change background colorsearchField.backgroundColor = [UIColor blueColor];// To change text colorsearchField.textColor = [UIColor redColor];// To change placeholder text colorsearchField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Some Text"];UILabel *placeholderLabel = [searchField valueForKey:@"placeholderLabel"];placeholderLabel.textColor = [UIColor grayColor];


Just try this code

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setBackgroundColor:[UIColor grayColor]];

OR

Try this

- (void)viewDidLoad    {        [super viewDidLoad];        //change the background color [[self searchViewForTextFieldBg:self.searchTextfield] setBackgroundColor:[UIColor grayColor]];//change the textcolorself.searchTextfield.textColor =[UIColor greenColor];    }    - (UITextField*)searchViewForTextFieldBg:(UIView*)view{    if ([view isKindOfClass:[UITextField class]]) {        return (UITextField*)view;    }    UITextField *searchTextField;    for (UIView *subview in view.subviews) {        searchTextField = [self searchViewForTextFieldBg:subview];        if (searchTextField) {            break;        }    }    return searchTextField;}