2

UISearchBar の内側の影を削除するにはどうすればよいですか?

試してみまし[[searchBar layer]setShadowOpacity:0]たが、何もしないようです。

4

3 に答える 3

4
  1. 必要な外観の背景画像を作成します。たとえば、 ここをクリックして、私が使用したエンド キャップ付きの 2 つの伸縮可能な画像を表示します。

  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 に答える