IOS 自定义搜索条

自定义搜索条继承自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);

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容