Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想更改默认 UISearchBar 的外观。例如,您将如何在 Google iPhone 应用程序中重新创建搜索框,如下所示?您将如何叠加图像以产生这种效果?
(来源:isedb.com)
在对自定义搜索栏的可能性进行一些调查后,我倾向于说这是一个与 无关的自定义组件,UISearchBar而是重新创建其功能。
UISearchBar
你不需要继承任何东西。创建一个具有按钮和文本字段的新 UIView,然后在整个视图将要加载时执行以下操作:
[self.searchDisplayController.searchBar addSubview:customSearchBarView];
确保将新文本字段设置为第一响应者,以便它可以访问键盘。