灰色 UISearchBar 以编程方式匹配范围栏
我正在尝试重新创建此 UISearchBar (如表搜索示例代码中所示):
alt text http://img168 .imageshack.us/img168/6378/43558113.png
我见过的所有示例都涉及使用 xib,但是我需要以编程方式执行此操作。问题是更改色调颜色也会更改取消按钮的色调:
alt text http://img243.imageshack.us/ img243/1375/screenshot20100527at944.png
有什么想法吗?
I'm trying to recreate this UISearchBar (as seen in the Table Search example code):
alt text http://img168.imageshack.us/img168/6378/43558113.png
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:
alt text http://img243.imageshack.us/img243/1375/screenshot20100527at944.png
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将搜索栏与 UISearchDisplayController 关联起来神奇地提供了许多标准外观和行为,例如:
在我的表视图控制器中,我做了以下操作:
Associating the search bar with a UISearchDisplayController magically provides a lot of standard look and behavior such as:
In my tableview controller I've done the following:
我完全同意斯科特·麦卡蒙的观点。
然而,在
setSearchDisplayController:
上使用performSelector:withObject:
并不是我的方法。这取决于随时可能更改的私有 API。如果苹果删除他们的私有实现,你的应用程序将会崩溃。更好的方法是重写视图控制器中的
searchDisplayController:
以返回UISearchDisplayController
的实例:I totally agree with Scott McCammon.
However using a
performSelector:withObject:
onsetSearchDisplayController:
would not be my approach. This depends on private API which can change at any moment. If Apple would remove their private implementation your app will crash.A better way would be to override the
searchDisplayController:
in your view controller to return your instance ofUISearchDisplayController
:我不明白是否需要调用
setSearchDisplayController:
或覆盖searchDisplayController
。在 iOS 4.3.2 下,initWithSearchBar:contentsController:
似乎为作为contentsController
参数传递的UIViewController
实例设置searchDisplayController
。也许这是早期 iOS 版本中的一个问题,但在当前版本中似乎是多余的。I don't understand the need for the call to
setSearchDisplayController:
or the override forsearchDisplayController
. Under iOS 4.3.2initWithSearchBar:contentsController:
appears to setsearchDisplayController
for theUIViewController
instance passed as thecontentsController
argument. Perhaps this was a problem in earlier iOS releases, but it appears redundant in the current release.