选择文本字段时,UISearchBar会更改背景

时间:2016-05-06 03:07:26

标签: ios swift uisearchbar

我希望UISearchBar的背景为黑色,但在选择文字字段时,它会向上滑动并将背景更改为灰色:

默认值:

enter image description here

-

选择时:

enter image description here

3 个答案:

答案 0 :(得分:0)

如果你想在UISearchBar的背景中设置黑色,那就试试吧..

UISearchBar *searchbar=[[UISearchBar alloc]init];
searchbar.barTintColor = [UIColor blackColor];

答案 1 :(得分:0)

UISearchBar具有translucent属性,请确保将其设置为false。

如果没有更多信息,我最好猜测为什么会发生这种情况:你的色调是黑色的,但它是半透明的,当它没有被选中时它会显示为黑色,因为下面没有视图,但是当它被选中时,它是白色的视图在它后面移动,导致黑色半透明看起来是灰色的。

答案 2 :(得分:0)

试试这个,

 [[UISearchBar appearance] setBackgroundColor:[UIColor blackColor]];
 [[UISearchBar appearance] setBarTintColor:[UIColor blackColor]];