// // searchBarView.m // 隐私保护 // // Created by xd h on 2025/3/4. // #import "searchBarView.h" @implementation searchBarView - (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; //self.backgroundColor = [UIColor clearColor]; [self drawAnyView]; return self; } -(void)drawAnyView { UIView *whiteBgView = [[UIView alloc] init]; whiteBgView.backgroundColor = [UIColor whiteColor]; [self addSubview:whiteBgView]; whiteBgView.layer.cornerRadius = 12; whiteBgView.layer.masksToBounds = YES; [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_equalTo(16); make.right.mas_equalTo(-16); make.bottom.mas_equalTo(0); }]; //搜索小图标 UIImageView *imageView = [[UIImageView alloc] init]; imageView.image = [UIImage imageNamed:@"home_search_icon"]; [whiteBgView addSubview:imageView]; [imageView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(24); make.height.mas_equalTo(24); make.left.mas_equalTo(9); make.centerY.mas_equalTo(0); }]; //左边搜索文字 UILabel *SearchLabel = [[UILabel alloc] init]; NSString *titleStr = NSLocalizedString(@"Search_nas_title",nil); SearchLabel.text = titleStr; SearchLabel.font = [UIFont systemFontOfSize:12]; SearchLabel.textColor = [UIColor hwColor:@"#7C8196" alpha:1.0]; [whiteBgView addSubview:SearchLabel]; [SearchLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(24); make.left.equalTo(imageView.mas_right).offset(2); make.centerY.mas_equalTo(0); }]; //右边搜索按钮 UIButton *searchBut = [[UIButton alloc] init]; [searchBut setTitle:titleStr forState:UIControlStateNormal]; [searchBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; searchBut.titleLabel.font = [UIFont systemFontOfSize:12.0]; searchBut.backgroundColor = [UIColor hwColor:@"#01B7EA" alpha:1.0]; searchBut.layer.cornerRadius = 10; searchBut.userInteractionEnabled = NO; [whiteBgView addSubview:searchBut]; [searchBut mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(32); make.width.mas_equalTo(48); make.right.mas_equalTo(-10); make.centerY.mas_equalTo(0); }]; } @end