我在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
。它也没有显示我正在输入的文字。但是,当我第二次点击时,它的表现正常。此外,它显示了一些黑色补丁。我的搜索栏看起来像这样:
答案 0 :(得分:-1)
This issue may be by adding this code
[[searchBar.subviews objectAtIndex:0] removeFromSuperview]; or
if ([level2SubView isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[level2SubView removeFromSuperview];
}
Please remove this and see.