2

如何删除 UISearchBar 的内部阴影?

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

4

3 回答 3

4
  1. 创建具有所需外观的背景图像。例如, 单击此处查看我使用的两个带有端盖的可拉伸图像。

  2. 使用以下 API:

    [self.searchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"search_field.png"] forState:UIControlStateNormal];
    
于 2013-02-20T09:37:46.243 回答
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。试试吧。

于 2013-06-14T02:54:02.397 回答
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;
        }
    }
于 2013-01-06T03:18:47.510 回答