// // KBSearchPopView.m // YouHuiProject // // Created by 小花 on 2018/5/9. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBSearchPopView.h" @implementation KBSearchPopView - (instancetype)initWithFrame:(CGRect)frame searchText:(NSString *)searchText{ self = [super initWithFrame:frame]; if (self) { self.layer.cornerRadius = 6; self.layer.masksToBounds = YES; self.backgroundColor = [UIColor whiteColor]; [self initSubViewWithText:searchText]; } return self; } - (void)initSubViewWithText:(NSString *)searchText { UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, Fitsize(85))]; imageView.image = [UIImage imageNamed:@"SearchPop_bg"]; [self addSubview:imageView]; UILabel *titleLb = [[UILabel alloc] initWithFrame:CGRectMake(0, Fitsize(20), self.width, 25)]; titleLb.text = @"智能省钱"; titleLb.font = [UIFont systemFontOfSize:16]; titleLb.textAlignment = NSTextAlignmentCenter; titleLb.textColor = [UIColor whiteColor]; [imageView addSubview:titleLb]; UILabel *desLb = [[UILabel alloc] initWithFrame:CGRectMake(0, titleLb.bottom, self.width, 17)]; desLb.text = @"您可能想搜索该商品"; desLb.font = [UIFont systemFontOfSize:12]; desLb.textAlignment = NSTextAlignmentCenter; desLb.textColor = [UIColor whiteColor]; [imageView addSubview:desLb]; UILabel *searchLabel = [[UILabel alloc] initWithFrame:CGRectMake(23, imageView.bottom+30, self.width-46, 60)]; searchLabel.numberOfLines = 3; searchLabel.textColor = [UIColor YHColorWithHex:0x262626]; searchLabel.textAlignment = NSTextAlignmentCenter; searchLabel.font = [UIFont systemFontOfSize:14]; searchLabel.text = searchText; [self addSubview:searchLabel]; UIButton *cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, self.height-57, self.width/2, 57)]; [cancelBtn setTitleColor:[UIColor YHColorWithHex:0x999999] forState:UIControlStateNormal]; [cancelBtn setTitle:@"取消" forState:UIControlStateNormal]; cancelBtn.titleLabel.font = [UIFont systemFontOfSize:16]; [cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:cancelBtn]; UIButton *searchBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.width/2, self.height-57, self.width/2, 57)]; [searchBtn setTitleColor:[UIColor homeRedColor] forState:UIControlStateNormal]; [searchBtn setTitle:@"搜索" forState:UIControlStateNormal]; searchBtn.titleLabel.font = [UIFont systemFontOfSize:16]; [searchBtn addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:searchBtn]; } - (void)cancelAction { if (self.cancelClick) { self.cancelClick(); } } - (void)searchClick { if (self.searchlClick) { self.searchlClick(); } } @end