【问题标题】:UISearchBar appearance issues in iOS 7iOS 7 中的 UISearchBar 外观问题
【发布时间】:2013-10-14 08:09:30
【问题描述】:

我在 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。它也没有显示我输入的文本。但是,当我第二次单击时,它的行为正常。此外,它显示了一些黑色补丁。我的搜索栏是这样的:

【问题讨论】:

    标签: iphone ios objective-c ipad uisearchbar


    【解决方案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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 1970-01-01
      • 2012-09-27
      • 1970-01-01
      • 2015-09-10
      相关资源
      最近更新 更多