zoukankan      html  css  js  c++  java
  • 搜索栏的自定义

    搜索框:UISearch
    1、自定义UISearch,继承UITextField,UISearBar不好用。

       相关属性:contentVerticalAlignment--文字居中设置

                    清除按钮--clearButtonMode

                    在左边添加一个view--leftView--显示图片放大安

                    placeholder--- 搜索提醒文字,(使用placeholder样式单一,无法改变样式,这里用另外一中方法)

    具体事例代码:

     1 // 背景
     2     UITextField * searchBar = [[UITextField alloc]init];
     3     searchBar.background = [UIImage resizeImageWithName:@"searchbar_textfield_background"];
     4     // 尺寸
     5     searchBar.frame = CGRectMake(0, 0, 300, 30);
     6     // 左边放大静
     7     UIImageView * iconView = [[UIImageView alloc]initWithImage:[UIImage imageWithNamed:@"searchbar_textfield_search_icon" ]];
     8     // 尺寸
     9     iconView.frame = CGRectMake(0, 0, 30, 30);
    10     iconView.contentMode = UIViewContentModeCenter;
    11     searchBar.leftView = iconView;
    12     searchBar.leftViewMode = UITextFieldViewModeAlways;
    13     // 字体
    14     searchBar.font = [UIFont systemFontOfSize:13];
    15     // 添加删除按钮
    16     searchBar.clearButtonMode = UITextFieldViewModeAlways;
    17     // 设置提醒文字
    18     NSMutableDictionary * attrs = [NSMutableDictionary dictionary];
    19     
    20     attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    21     searchBar.attributedPlaceholder = [[NSAttributedString alloc]initWithString:@"搜索" attributes:attrs];
    22     // 设置中间的标题内容
    23     self.navigationItem.titleView = searchBar;

      2、当在搜索栏,弹出的键盘右下角显示搜索按钮:

    // 设置键盘右下角按钮的样式
            self.returnKeyType = UIReturnKeySearch;
            
    

          注意:①如果想要显示汉字“搜索”,首先要将模拟器的语言换成中文,在切换键盘输入法为简体拼音

                  ②当搜索栏没有任何输入时,键盘上的搜索按钮不应能点击,需要设置一个属性

                     self.enablesReturnKeyAutomatically = YES;

  • 相关阅读:
    android HashMap的几种遍历方法
    Android android:windowSoftInputMode属性详解
    Linux环境变量的设置和查看方法
    linux 定时执行shell脚本
    Linux 定时执行shell脚本_crontab
    Linux下修改字符集,转自
    解决Linux下Oracle中文乱码的一些心得体会 ,转自
    SSH Secure Shell Client连接Linux 命令行显示中文乱码问题 和oracle 查询数据中文乱码问题
    VMware 虚拟机(linux)增加根目录磁盘空间 转自
    linux 虚机增加硬盘大小 转自
  • 原文地址:https://www.cnblogs.com/angongIT/p/3776426.html
Copyright © 2011-2022 走看看