且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ios8中更改UISearchBar文本字段背景颜色和文本颜色

更新时间:2023-01-27 20:04:53

试试这个:

UITextField *searchField = [self.searchBar valueForKey:@"searchField"];

// To change background color
searchField.backgroundColor = [UIColor blueColor];

// To change text color
searchField.textColor = [UIColor redColor];

// To change placeholder text color
searchField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Some Text"];
UILabel *placeholderLabel = [searchField valueForKey:@"placeholderLabel"];
placeholderLabel.textColor = [UIColor grayColor];