gpt4 book ai didi

iphone - 灰色 UISearchBar 以编程方式匹配范围栏

转载 作者:行者123 更新时间:2023-12-03 18:33:26 28 4
gpt4 key购买 nike

我正在尝试重新创建此 UISearchBar(如表搜索示例代码中所示):

alt text http://img168.imageshack.us/img168/6378/43558113.png

我见过的所有执行此操作的示例都涉及使用 xib,但是我需要以编程方式执行此操作。问题是更改色调颜色也会更改取消按钮的色调:

alt text http://img243.imageshack.us/img243/1375/screenshot20100527at944.png

有什么想法吗?

最佳答案

将搜索栏与 UISearchDisplayController 关联起来可以神奇地提供许多标准外观和行为,例如:

  • 灰色调不影响取消按钮
  • 自动显示/隐藏取消按钮
  • 调整任何表格 View 索引的宽度

在我的表格 View Controller 中,我完成了以下操作:

- (void)viewDidLoad {
[super viewDidLoad];

// setup searchBar and searchDisplayController

UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[searchBar sizeToFit];
searchBar.delegate = self;
searchBar.placeholder = @"Search";
self.tableView.tableHeaderView = searchBar;

UISearchDisplayController *searchDC = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];

// The above assigns self.searchDisplayController, but without retaining.
// Force the read-only property to be set and retained.
[self performSelector:@selector(setSearchDisplayController:) withObject:searchDC];

searchDC.delegate = self;
searchDC.searchResultsDataSource = self;
searchDC.searchResultsDelegate = self;

[searchBar release];
[searchDC release];
}

关于iphone - 灰色 UISearchBar 以编程方式匹配范围栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2959299/

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