zoukankan      html  css  js  c++  java
  • IOS--常用控件--UISearchBar和UISearchDisplayController

    一、UISearchBar单独使用时,设置样式:

    UIView *view =[mySearchBar.subviews objectAtIndex:0];

        //    view.backgroundColor =[UIColor clearColor];

        for (UIView *backview in view.subviews) {

            if ([backview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {

                [backview removeFromSuperview];

                break;

            }

        }

    二、UISearchBar和UISearchDisplayController结合使用时:

    • 关于代理
     // searchResultsDataSource 就是 UITableViewDataSource
     searchDisplayController.searchResultsDataSource = self;
     // searchResultsDelegate 就是 UITableViewDelegate
     searchDisplayController.searchResultsDelegate = self;
    

    别忘了这个:

    searchDisplayController.delegate = self;
    
    • 如果想设置 cancelbutton的颜色:
     searchBar.tintColor = [UIColor whiteColor];
    
    • 如果想设置 cancelbutton的字体: 在IOS7下这样设置:
    -(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
     self.searchDisplayController.searchBar.showsCancelButton = YES;
     UIButton *cancelButton;
     UIView *topView = self.searchDisplayController.searchBar.subviews[0];
     for (UIView *subView in topView.subviews) {
     if ([subView isKindOfClass:NSClassFromString(@"UINavigationButton"))]) {
     cancelButton = (UIButton*)subView;
    }
    }
     if (cancelButton) {
     //Set the new title of the cancel button
     [cancelButton setTitle:@"Annuller"forState:UIControlStateNormal];
    }
    }
    

    在IOS5/6下这样设置:

    - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
     self.searchDisplayController.searchBar.showsCancelButton = YES;
     UIButton *cancelButton = nil;
     for (UIView *subView in self.searchDisplayController.searchBar.subviews) {
     if ([subView isKindOfClass:UIButton)]) {
     cancelButton = (UIButton*)subView;
    }
    }
     if (cancelButton){
     //Set the new title of the cancel button
     [cancelButton setTitle:@"Annuller"forState:UIControlStateNormal];
    }
    }
    
    • 如果想设置 UISearchBar的背景颜色可以这样设置:
    searchDisplayController.searchBar.barTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"nav_bg"]];
    
    • 设置UISearchDisplayController是否激活: eg:当我点击 搜索列表 的时候,我想让 searchbar恢复原状,即导航栏也恢复原状时;
    [searchDisplayController setActive:NO animated:YES];
  • 相关阅读:
    C# 根据主窗体的位置弹窗信息窗体一直保持在主窗体中间
    c# winForm父子窗口 通过委托进行信息传递
    使用devexpress插件 消除运行时弹窗
    C# 获取当前时间戳
    WinForm实现Loading等待界面
    转载 C#设置控件 Enabled 为 false 时背景色不改变
    DEV gridView中加入加载条显示进度,必须为圆角型
    winfrom 圆角化
    列表元素的反转、排序——python
    使用for循环和while循环打印九九乘法表——python
  • 原文地址:https://www.cnblogs.com/howdoudo/p/4313574.html
Copyright © 2011-2022 走看看