iOS-在导航栏添加搜索框

说白了,就是在navigationcotroller中,显示一个view,具体实现可参考如下代码

    CGRect mainViewBounds = self.navigationController.view.bounds;
    UISearchBar *customSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(CGRectGetWidth(mainViewBounds)/2-((CGRectGetWidth(mainViewBounds)-120)/2), CGRectGetMinY(mainViewBounds)+22, CGRectGetWidth(mainViewBounds)-120, 40)];
    customSearchBar.delegate = self;
    customSearchBar.showsCancelButton = NO;
    customSearchBar.searchBarStyle = UISearchBarStyleMinimal;
    [self.navigationController.view addSubview: customSearchBar];

 

posted @ 2016-07-26 21:20  tomandhua  阅读(11481)  评论(0编辑  收藏  举报