[英]TextField text Color change in searchbar
請檢查下面的代碼,我使用了一個包含搜索searchbar
navigationbar
searchbar
並且搜索searchbar
具有文本字段,現在我想更改文本textfield
的文本顏色,我做了下面的代碼,但是它不起作用,因此請幫助糾正它。
[[UISearchBar appearanceWhenContainedInInstancesOfClasses:@[[UINavigationBar class]]]setTintColor:[UIColor whiteColor]];
[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]]setTextColor:[UIColor whiteColor]];
嘗試這個,
NSArray *searchBarSubViews = [[self.searchBar.subviews objectAtIndex:0] subviews];
for (UIView *view in searchBarSubViews) {
if([view isKindOfClass:[UITextField class]])
{
UITextField *txt = (UITextField*)view;
UIImageView *imgView = (UIImageView*)textField.leftView;
imgView.image = [imgView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
imgView.tintColor = [UIColor whiteColor];
txt.backgroundColor = [UIColor blackColor];
txt.textColor = [UIColor RedColor];
UIButton *btnClear = (UIButton*)[textField valueForKey:@"clearButton"];
[btnClear setImage:[btnClear.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
btnClear.tintColor = [UIColor whiteColor];
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.