UISearchBar修改placeholder的颜色

正确设置方法

    for (UIView* subview in [[self.searchBar.subviews lastObject] subviews]) {
        if ([subview isKindOfClass:[UITextField class]]) {
            UITextField *textField = (UITextField*)subview;
            //修改placeholder的颜色
            [textField setValue:CYCOLOR(0x333333) forKeyPath:@"_placeholderLabel.textColor"];
        }
    }

错误设置方法

 [self.searchBar setValue:CYCOLOR(0x333333) forKeyPath:@"_placeholderLabel.textColor"];

这样设置还是无效的.

你可能感兴趣的:(UISearchBar修改placeholder的颜色)