zoukankan      html  css  js  c++  java
  • 新浪微博客户端(5)-自定义UISearchBar

    iOS自带的UISearchBar有很多限制,我们可以使用UITextField做出一个类似于SearchBar的效果。

    //=================================================
        //                 自定义SearchBar
        //=================================================
        
        // 1.创建一个UITextField作为背景
        UITextField *searchBar = [[UITextField alloc] init];
        searchBar.width = 420;
        searchBar.height = 30;
        searchBar.font = [UIFont systemFontOfSize:14];
        searchBar.background = [UIImage imageNamed:@"searchbar_textfield_background"];
    
        // 2.添加左侧的小图标
    //    UIImage *searchIcon = [UIImage imageNamed:@"searchbar_textfield_search_icon"];
    //    UIImageView *searchIconView = [[UIImageView alloc] initWithImage:searchIcon]; // 使用此种形式创建出来的ImageView是有默认大小的。
        
        UIImageView *searchIconView = [[UIImageView alloc] init];
        searchIconView.image = [UIImage imageNamed:@"searchbar_textfield_search_icon"];
        searchIconView.width = 30;
        searchIconView.height = 30;
        
        searchIconView.contentMode = UIViewContentModeCenter;
        searchBar.leftView = searchIconView;
        searchBar.leftViewMode = UITextFieldViewModeAlways;
        
        self.navigationItem.titleView = searchBar;

    最终效果:

  • 相关阅读:
    数据库的基本操作
    这是数据库的知识了
    这就全都是了解的东西啦
    互斥锁
    我只会用threading,我菜
    violet
    网络编程II
    网络编程
    这是网络编程的一小步,却是我的一大步
    莫比乌斯反演(一)从容斥到反演
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/5967662.html
Copyright © 2011-2022 走看看