searchBarView.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. UIImageView *imageView = [[UIImageView alloc] init];
  30. imageView.image = [UIImage imageNamed:@"home_search_icon"];
  31. [whiteBgView addSubview:imageView];
  32. [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.width.mas_equalTo(24);
  34. make.height.mas_equalTo(24);
  35. make.left.mas_equalTo(9);
  36. make.centerY.mas_equalTo(0);
  37. }];
  38. //左边搜索文字
  39. UILabel *SearchLabel = [[UILabel alloc] init];
  40. NSString *titleStr = NSLocalizedString(@"Search_nas_title",nil);
  41. SearchLabel.text = titleStr;
  42. SearchLabel.font = [UIFont systemFontOfSize:12];
  43. SearchLabel.textColor = [UIColor hwColor:@"#7C8196" alpha:1.0];
  44. [whiteBgView addSubview:SearchLabel];
  45. [SearchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.height.mas_equalTo(24);
  47. make.left.equalTo(imageView.mas_right).offset(2);
  48. make.centerY.mas_equalTo(0);
  49. }];
  50. //右边搜索按钮
  51. UIButton *searchBut = [[UIButton alloc] init];
  52. [searchBut setTitle:titleStr forState:UIControlStateNormal];
  53. [searchBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  54. searchBut.titleLabel.font = [UIFont systemFontOfSize:12.0];
  55. searchBut.backgroundColor = [UIColor hwColor:@"#01B7EA" alpha:1.0];
  56. searchBut.layer.cornerRadius = 10;
  57. searchBut.userInteractionEnabled = NO;
  58. [whiteBgView addSubview:searchBut];
  59. [searchBut mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.height.mas_equalTo(32);
  61. make.width.mas_equalTo(48);
  62. make.right.mas_equalTo(-10);
  63. make.centerY.mas_equalTo(0);
  64. }];
  65. }
  66. @end