灰色UISearchBar以编程方式匹配范围栏 [英] Gray UISearchBar w/matching scope bar programmatically

查看:129
本文介绍了灰色UISearchBar以编程方式匹配范围栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to recreate this UISearchBar (as seen in the Table Search example code):

替代文字http://img168.imageshack.us/img168/6378/43558113.png

全部我看到这样做的例子涉及使用xib,但是我需要以编程方式进行。问题是改变色调颜色也会改变取消按钮的色调:

All the examples I've seen to do this involve using a xib, however I need to do it programmatically. The problem is changing the tint color also changes the cancel button's tint:

替代文字http://img243.imageshack.us/img243/1375/screenshot20100527at944.png

任何想法?

推荐答案

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

Associating the search bar with a UISearchDisplayController magically provides a lot of standard look and behavior such as:


  • 灰色色调,不影响取消按钮

  • 自动显示/隐藏取消按钮

  • 围绕任何tableview的宽度调整索引

在我的tableview控制器中,我完成了以下操作:

In my tableview controller I've done the following:

- (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];
}

这篇关于灰色UISearchBar以编程方式匹配范围栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆