1

このUISearchBarに色を付けて、背景とシームレスに見えるようにしようとしています(2番目の画像のように)。これを行うことは可能ですか?IBでプログラムで設定してみましたが、うまくいきませんでした。

助けてくれてありがとう

UISearchBarのスクリーンショット

目的の外観は次のとおりです。

UISearchBarスクリーンショット-希望の外観

4

2 に答える 2

1

このようにTintカラーを設定するだけです..

    [searchBar setBarStyle:UIBarStyleDefault];
    [searchBar setTintColor:[UIColor colorWithRed:.81 green:.14 blue:.19 alpha:1]];//set alpha with your requirement 

画像でもこのコードを使用すると、うまく機能します..

   for (UIView *subview in searchBar.subviews) {
        if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
            UIView *bg = [[UIView alloc] initWithFrame:subview.frame];
            bg.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"top-bar.png"]];
            [searchBar insertSubview:bg aboveSubview:subview];
            [subview removeFromSuperview];
            break;
        }
    }

そして、赤い色の検索バー全体については、このコードメイトを単純にコピーして貼り付けます..ここで私はこの問題を解決します

    for (UIView *subview in searchBar.subviews) {
        if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
            UIView *bg = [[UIView alloc] initWithFrame:subview.frame];
            bg.backgroundColor = [UIColor redColor];
            [searchBar insertSubview:bg aboveSubview:subview];
            [subview removeFromSuperview];
            break;
        }
    }
    [searchBar setTintColor:[UIColor redColor]];
于 2012-11-22T11:26:53.950 に答える