自定义控件

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];

}

你可能感兴趣的:(自定义控件)