删除UISearchBar的内部阴影

时间:2013-01-06 02:25:05

标签: objective-c ios uisearchbar uisearchdisplaycontroller

如何删除UISearchBar的内部阴影?

我已经尝试了[[searchBar layer]setShadowOpacity:0],但似乎没有做任何事情。

3 个答案:

答案 0 :(得分:5)

  1. 创建具有所需外观的背景图像。例如, click here使用我使用过的大写字母来查看两个可伸缩的图像。

  2. 使用以下API:

    [self.searchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"search_field.png"] forState:UIControlStateNormal];
    

答案 1 :(得分:3)

    UITextField *textField = nil;

    for( UIView *subview in searchBar.subviews )
    { 
       if ([subview isKindOfClass:[UITextField class]]) {
            textField = (UITextField *)subview;
            textField.borderStyle = UITextBorderStyleNone;
            textField.layer.borderWidth = 1.f;
            textField.layer.borderColor = [UIColor lightGrayColor].CGColor;
            textField.layer.cornerRadius = 14.0f;
            textField.background = nil;
            textField.backgroundColor = [UIColor whiteColor];
        }
    }

使用此代码可以删除UISearchBar的Inner Shadow.try它。

答案 2 :(得分:2)

    for( UIView *subview in searchBar.subviews )
    {
        if( [subview isKindOfClass:NSClassFromString( @"UISearchBarBackground" )] )
        {
            //   you can set the textField backgroundColor clearColor like below.
            //  [subview setAlpha:0.0f];
            //  break;


            //   or you can set textField backgroundColor solid color like below
            UIView *aView = [[UIView alloc] initWithFrame:subview.bounds];
            aView.backgroundColor = [UIColor greenColor];
            [subview addSubview:aView];
            break;
        }
    }