IOS 简单实现在导航栏处添加SearchBar

{app.params.name}} {app.params.name}} {app.params.name}}

导航栏出添加搜索框,应该是大多数app应用中需要使用的,这里简单展示一下添加的方法

CGRect mainViewBounds = self.navigationController.view.bounds;
customSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
                                                            CGRectGetMinY(mainViewBounds) + 44.0,
                                                            self.navigationController.view.bounds.size.width,
                                                            40)];
customSearchBar.delegate = self;
customSearchBar.showsCancelButton = YES;
[self.navigationController.view addSubview: customSearchBar];
CGRect viewBounds = self.navigationController.view.bounds;
[self.view setFrame:CGRectMake(CGRectGetMinX(viewBounds),
                               CGRectGetMinY(viewBounds) + 40,
                               CGRectGetWidth(viewBounds),
                               CGRectGetHeight(viewBounds) - 128)];

实现效果还是不错的


版权声明

durban 创作并维护的 Gowhich 博客采用 创作共用保留署名-非商业-禁止演绎4.0国际许可证。

本文首发于 Gowhich 博客( https://www.gowhich.com ),版权所有,侵权必究。

本文永久链接: https://www.gowhich.com/blog/458

comments powered by Disqus