searchBarView.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // searchBarView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2025/3/4.
  6. //
  7. #import "searchBarView.h"
  8. @implementation searchBarView
  9. - (id)initWithFrame:(CGRect)frame{
  10. self = [super initWithFrame:frame];
  11. //self.backgroundColor = [UIColor clearColor];
  12. [self drawAnyView];
  13. return self;
  14. }
  15. -(void)drawAnyView
  16. {
  17. UIView *whiteBgView = [[UIView alloc] init];
  18. whiteBgView.backgroundColor = [UIColor whiteColor];
  19. [self addSubview:whiteBgView];
  20. whiteBgView.layer.cornerRadius = 12;
  21. whiteBgView.layer.masksToBounds = YES;
  22. [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  23. make.top.mas_equalTo(0);
  24. make.left.mas_equalTo(16);
  25. make.right.mas_equalTo(-16);
  26. make.bottom.mas_equalTo(0);
  27. }];
  28. //添加手势事件
  29. [whiteBgView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didClickWhiteViewFun)]];
  30. //搜索小图标
  31. UIImageView *imageView = [[UIImageView alloc] init];
  32. imageView.image = [UIImage imageNamed:@"home_search_icon"];
  33. [whiteBgView addSubview:imageView];
  34. [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.width.mas_equalTo(24);
  36. make.height.mas_equalTo(24);
  37. make.left.mas_equalTo(9);
  38. make.centerY.mas_equalTo(0);
  39. }];
  40. //左边搜索文字
  41. UILabel *SearchLabel = [[UILabel alloc] init];
  42. NSString *titleStr = NSLocalizedString(@"Search_nas_title",nil);
  43. SearchLabel.text = titleStr;
  44. SearchLabel.font = [UIFont systemFontOfSize:12];
  45. SearchLabel.textColor = [UIColor hwColor:@"#7C8196" alpha:1.0];
  46. [whiteBgView addSubview:SearchLabel];
  47. [SearchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.height.mas_equalTo(24);
  49. make.left.equalTo(imageView.mas_right).offset(2);
  50. make.centerY.mas_equalTo(0);
  51. }];
  52. //右边搜索按钮
  53. UIButton *searchBut = [[UIButton alloc] init];
  54. [searchBut setTitle:titleStr forState:UIControlStateNormal];
  55. [searchBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  56. searchBut.titleLabel.font = [UIFont systemFontOfSize:12.0];
  57. searchBut.backgroundColor = [UIColor hwColor:@"#01B7EA" alpha:1.0];
  58. searchBut.layer.cornerRadius = 10;
  59. searchBut.userInteractionEnabled = NO;
  60. [whiteBgView addSubview:searchBut];
  61. [searchBut mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.height.mas_equalTo(32);
  63. make.width.mas_equalTo(48);
  64. make.right.mas_equalTo(-10);
  65. make.centerY.mas_equalTo(0);
  66. }];
  67. }
  68. - (void)didClickWhiteViewFun
  69. {
  70. if (_didClickBgFun) {
  71. _didClickBgFun();
  72. }
  73. }
  74. @end