gpt4 book ai didi

iphone - 是否可以更改 UISearchDisplayController 搜索栏的边框颜色?

转载 作者:行者123 更新时间:2023-12-03 19:15:09 24 4
gpt4 key购买 nike

我使用以下代码添加了一个 UISearchBar 作为表头。

searchBar = [[UISearchBar alloc] initWithFrame:self.tableView.bounds];
searchBar.tintColor = [UIColor colorWithWhite:185.0/255 alpha:1.0];
[searchBar sizeToFit];
self.tableView.tableHeaderView = searchBar;

然后我按如下方式设置我的 UISearchDisplayController

searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
[searchDisplayController setDelegate:self];
[searchDisplayController setSearchResultsDataSource:self];

一切都按照我想要的方式运行,除了UISearchDisplayController在搜索栏上方添加了一个蓝色(ish)边框 - 该栏无法识别我设置的tintColor在搜索栏上。

是否可以更改此栏的颜色?这显然不是绝对重要的,但如果这条线保持这样的蓝色,我将永远烦恼!

zoomed in on UISearchBar http://nikonizer.yfrog.com/Himg256/scaled.php?tn=0&server=256&filename=4y9.png&xsize=640&ysize=640

最佳答案

边框似乎不太适合色调颜色的变化,所以我的设计师坚持要求我们更改它。就像在搜索栏底部添加 1px View 一样简单:

现在在 viewDidLoad 中,我创建一个 1px View 并将其放置在搜索栏的最底部。

#define SEARCHBAR_BORDER_TAG 1337
- (void) viewDidLoad{
// Set a custom border on the bottom of the search bar, so it's not so harsh
UISearchBar *searchBar = self.searchDisplayController.searchBar;
UIView *bottomBorder = [[UIView alloc] initWithFrame:CGRectMake(0,searchBar.frame.size.height-1,searchBar.frame.size.width, 1)];
[bottomBorder setBackgroundColor:[UIColor colorWithWhite:200.0f/255.f alpha:1.0f]];
[bottomBorder setOpaque:YES];
[bottomBorder setTag:SEARCHBAR_BORDER_TAG];
[searchBar addSubview:bottomBorder];
[bottomBorder release];
}

现在,当用户实际搜索时,我还将色调颜色转换回默认颜色,因为搜索栏着色也会将取消按钮颜色着色为丑陋的颜色。如果您执行类似的操作,下面的代码将隐藏/显示每个状态的边框:

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
[controller.searchBar setTintColor:nil];

// Hide our custom border
[[controller.searchBar viewWithTag:SEARCHBAR_BORDER_TAG] setHidden:YES];
}

- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller{
[controller.searchBar setTintColor:[UIColor colorWithRed:238.0f/255.0f green:245.0f/255.0f blue:248.0f/255.0f alpha:1.0f]];
//Show our custom border again
[[controller.searchBar viewWithTag:SEARCHBAR_BORDER_TAG] setHidden:NO];
}

关于iphone - 是否可以更改 UISearchDisplayController 搜索栏的边框颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2702848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com