UISearchBar で iOS の問題に直面しています。UISearchBar をカスタマイズするために次のコードを使用しています。
- (void)showSearchBarCustomColorAndDesignWithTargetForiOS7:(id)target{
UIView * subview;
NSArray * subviews = [self subviews];
for (subview in subviews){
for (UIView *level2SubView in subview.subviews){
if ([level2SubView isKindOfClass:[UITextField class]])
{
[((UITextField*)level2SubView) setEnablesReturnKeyAutomatically:NO];
((UITextField*)level2SubView).delegate=target;
[((UITextField*)level2SubView) setEnabled:TRUE];
((UITextField*)level2SubView).borderStyle = UITextBorderStyleLine;
((UITextField*)level2SubView).textColor = [UIColor whiteColor];
((UITextField*)level2SubView).font =[UIFont fontWithName:@"ProximaNova-Light" size:24.0];
((UITextField*)level2SubView).autocorrectionType = UITextAutocorrectionTypeNo;
((UITextField*)level2SubView).layer.borderWidth = 1.0;
((UITextField*)level2SubView).layer.borderColor = UIColorFromRGB(0x2774A7).CGColor;
[[((UITextField*)level2SubView) valueForKey:@"textInputTraits"] setValue:[UIColor whiteColor] forKey:@"insertionPointColor"];
((UITextField*)level2SubView).autocapitalizationType = UITextAutocapitalizationTypeNone;
break;
}
if ([level2SubView isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[level2SubView removeFromSuperview];
}
}
}
self.delegate = target;
[self setImage:[UIImage imageNamed:@"search_white.png"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
[self setImage:[UIImage imageNamed:@"delete_white.png"] forSearchBarIcon:UISearchBarIconClear state:UIControlStateNormal];
[self setBackgroundColor:UIColorFromRGB(0x2774A7)];
}
初めて UISearchBar をクリックするたびに、それは呼び出されませんsearchBarShouldBeginEditing
。また、入力しているテキストが表示されません。ただし、2 回目にクリックすると、正しく動作します。また、いくつかの黒いパッチが表示されます。私の検索バーは次のようになっています。