如何删除 UISearchBar 的内部阴影?
我试过[[searchBar layer]setShadowOpacity:0]
了,但这似乎没有做任何事情。
如何删除 UISearchBar 的内部阴影?
我试过[[searchBar layer]setShadowOpacity:0]
了,但这似乎没有做任何事情。
创建具有所需外观的背景图像。例如, 单击此处查看我使用的两个带有端盖的可拉伸图像。
使用以下 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;
}
}