【问题标题】:iOS: UISearchBar background issueiOS:UISearchBar 后台问题
【发布时间】:2013-12-19 20:49:29
【问题描述】:

我正在尝试更改搜索栏的背景颜色。我希望这个顶视图是一种纯色。这是我正在使用的代码:

 [titleBarView setBackgroundColor:[ColorUtil colorWithHexString:@"1ABC9C"]];
searchBar.barTintColor=[ColorUtil colorWithHexString:@"1ABC9C"];
searchBar.backgroundColor=[ColorUtil colorWithHexString:@"1ABC9C"];

下面是我得到的结果。请注意,搜索栏的顶部和底部边缘有一些灰色。我该如何摆脱它?

编辑:添加后

 searchBar.searchBarStyle=UISearchBarStyleMinimal;

我现在明白了:

所以我原来的问题解决了,但是现在 searchBar 的内部颜色是错误的。什么属性支配它?

【问题讨论】:

  • 您的视图层次结构如何?你试过[searchBar setBarTintColor:[UIColor clearColor]];
  • 这对我有用。请创建一个答案,以便我接受。

标签: ios iphone background uisearchbar


【解决方案1】:

您的视图层次结构如何?你试过[searchBar setBarTintColor:[UIColor clearColor]];

【讨论】:

    【解决方案2】:

    试试:
    searchBar.searchBarStyle = UISearchBarStyleMinimal;

    参考:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISearchBar_Class/Reference.html

    【讨论】:

    • 请看我的编辑。这解决了我原来的问题,但改变了酒吧内部的颜色。
    • @JamesHarpe :只是把它放在那里......解决非白色搜索栏字段背景,这里:stackoverflow.com/a/12598711/2857130
    猜你喜欢
    • 2020-04-10
    • 2012-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-20
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    相关资源
    最近更新 更多