自定义搜索条继承自UITextField。
-(instancetype)initWithFrame:(CGRect)frame{
self= [superinitWithFrame:frame];
if(self) {
self.backgroundColor=HEX_COLOR(0xffffff);
self.layer.cornerRadius=14;
self.layer.masksToBounds=YES;
NSAttributedString* placeString = [[NSAttributedStringalloc]initWithString:@"输入商家名、品类或商圈"attributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:12.0f],NSForegroundColorAttributeName:HEX_COLOR(0xc4c4c4)}];
self.attributedPlaceholder= placeString;
//图片距离左边14
UIImageView*searchIcon = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"JHLivePlayBundle.bundle/search.tiff"]];
searchIcon.frame=CGRectMake(14, (frame.size.height-12) /2,12,12);
UIView* leftView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,26, frame.size.height)];
[leftViewaddSubview:searchIcon];
self.leftView= leftView;
self.leftViewMode=UITextFieldViewModeAlways;
}
returnself;
}
- (CGRect)placeholderRectForBounds:(CGRect)bounds{
returnCGRectInset(bounds,34,4);
}
网友评论