UISearchBar の内側の影を削除するにはどうすればよいですか?
試してみまし[[searchBar layer]setShadowOpacity:0]
たが、何もしないようです。
UISearchBar の内側の影を削除するにはどうすればよいですか?
試してみまし[[searchBar layer]setShadowOpacity:0]
たが、何もしないようです。
必要な外観の背景画像を作成します。たとえば、 ここをクリックして、私が使用したエンド キャップ付きの 2 つの伸縮可能な画像を表示します。
次の API を使用します。
[self.searchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"search_field.png"] forState:UIControlStateNormal];
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 を削除できます。試してみてください。
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;
}
}