码迷,mamicode.com
首页 > 其他好文 > 详细

UITextField

时间:2015-03-01 22:15:40      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

    1.自定义搜索框
    UITextField *searchBar = [[UITextField alloc]init];
    searchBar.width = 300;
    searchBar.height = 30;
    //设置搜索框背景图片
    searchBar.background = [UIImage resizedImage:@"searchbar_textfield_background"];
    //设置内容居中:如果找到不到合适的属性,就去父类中找,contentVerticalAlignment就是父类中的属性
    searchBar.contentVerticalAlignment =  UIControlContentVerticalAlignmentCenter;
    //设置左边显示一个放大镜
    UIImageView *leftview = [[UIImageView alloc]init];
    leftview.image = [UIImage imageNamed:@"searchbar_textfield_search_icon"];
    leftview.width =30;
    leftview.height = searchBar.height;
    leftview.contentMode = UIViewContentModeCenter;  //leftView居中显示
    searchBar.leftViewMode = UITextFieldViewModeAlways;  //设置总是显示
    searchBar.leftView = leftview;
    //设置右边显示删除按钮
    searchBar.clearButtonMode = UITextFieldViewModeAlways;
    self.navigationItem.titleView = searchBar;

 

UITextField

标签:

原文地址:http://www.cnblogs.com/jsnan/p/4307597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!