Im facing issues with iOS in UISearchBar. I'm using following code to Customize 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)];
}
Whenever I click on UISearchBar first time it's not calling searchBarShouldBeginEditing
. Also it's not showing the text I'm entering. However, when I click second time it's behaving properly. Also, it's showing some black patch. My Search bar is looking like this :
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.