0

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 回目にクリックすると、正しく動作します。また、いくつかの黒いパッチが表示されます。私の検索バーは次のようになっています。

ここに画像の説明を入力

4

1 に答える 1

-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.
于 2013-12-13T09:54:05.897 に答える