• 更改IOS于UISearchBar撤消button底、搜索输入文本框背景中的内容和UISearchBar底


     转载请标明出处:http://blog.csdn.net/android_ls/article/details/39993433

    測试的手机IOS系统版本为:6.1.3,实现过程例如以下:

    1、加入UISearchBar到父View

        _searchBar = [[UISearchBar alloc]init];
        _searchBar.frame = CGRectMake(0, 0, self.view.frame.size.width, kSeachBarH);
        _searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        _searchBar.delegate = self;
        _searchBar.placeholder = @"请输入姓名、公司名称、公司产品名称";
        [self.view addSubview:_searchBar];
    2、改动搜索框背景
        UIImage *img = [UIImage resizedImage:@"find_bg.png"];
        [_searchBar setBackgroundImage:img];
    3、改动搜索输入框内左側的指示图标

        [_searchBar setImage:[UIImage resizedImage:@"ic_search.png"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];

    4、改动搜索输入文本的背景

        [_searchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"login_btn_input_side.png"] forState:UIControlStateNormal];

         注:对于设计人员提供的搜索输入文本的背景。若提供的是一个圆角的小方块,按常理我们会使用拉伸图片的中间部分的方法,经測试显示效果例如以下:


         若让设计人员又一次提供一张固定高度的图片(比方高是60),当做搜索输入文本的背景。效果图例如以下:


    5、改动UISearchBar右側的取消button文字颜色及背景图片

    #pragma mark 搜索框的代理方法,搜索输入框获得焦点(聚焦)
    -(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
    {
        [searchBar setShowsCancelButton:YES animated:YES];
    
        // 改动UISearchBar右側的取消button文字颜色及背景图片
        for (UIView *searchbuttons in [searchBar subviews]){
            if ([searchbuttons isKindOfClass:[UIButton class]]) {
                UIButton *cancelButton = (UIButton*)searchbuttons;
                // 改动文字颜色
                [cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                [cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
                
                // 改动button背景
                [cancelButton setBackgroundImage:[UIImage resizedImage:@"login_btn_login.png"] forState:UIControlStateNormal];
                [cancelButton setBackgroundImage:nil forState:UIControlStateHighlighted];
            }
        }
    }
    注:改动取消button文字颜色及背景图片的代码片段,一定要放到取消button会显示代理方法中改动,否则遍历找不着呀,那就改动不了了。



    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    win2K/win2003终端服务器超出最大允许连接数解决之道
    DOM与SAX读取xml文件例程
    ubuntu安装配置telnet
    SCTP 简介
    groovy 脚本中文乱码问题解决
    编码问题研究
    gvim支持utf8
    ctags使用方法
    我家猫病了。。
    小朋友搞笑造句
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4910824.html
Copyright © 2020-2023  润新知