美文网首页
自定义控件

自定义控件

作者: 天亮説晚安 | 来源:发表于2015-12-16 22:04 被阅读22次

    YZSearchBar.h

    #import@interface YZSearchBar : UITextField

    +(instancetype)searchBar;

    @end

    YZSearchBar.m

    #import "YZSearchBar.h"

    #import "UIView+Extension.h"

    @implementation YZSearchBar

    -(id)initWithFrame:(CGRect)frame 

    {

         if(self = [super initWithFrame:frame])

    {

    self.font = [UIFont systemFontOfSize:13];

    self.placeholder = @"请输入搜索条件";

    [self setBackground:[UIImage imageNamed:@"searchbar_textfield_background"]];

    UIImageView * searchIcon = [[UIImageView alloc]init];

    searchIcon.image = [UIImage imageNamed:@"searchbar_textfield_search_icon"];

    searchIcon.width = 30;

    searchIcon.height = 30;

    searchIcon.contentMode = UIViewContentModeCenter;

    self.leftView = searchIcon;

    self.leftViewMode = UITextFieldViewModeAlways;

    }

    return self;

    }

    +(instancetype)searchBar

    {

    return [[self alloc]init];

    }

    相关文章

      网友评论

          本文标题:自定义控件

          本文链接:https://www.haomeiwen.com/subject/ilqphttx.html