このUISearchBarに色を付けて、背景とシームレスに見えるようにしようとしています(2番目の画像のように)。これを行うことは可能ですか?IBでプログラムで設定してみましたが、うまくいきませんでした。
助けてくれてありがとう
目的の外観は次のとおりです。
このUISearchBarに色を付けて、背景とシームレスに見えるようにしようとしています(2番目の画像のように)。これを行うことは可能ですか?IBでプログラムで設定してみましたが、うまくいきませんでした。
助けてくれてありがとう
目的の外観は次のとおりです。
このように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]];