ASBaseViewController.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // ASBaseViewController.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/4/24.
  6. //
  7. #import "ASBaseViewController.h"
  8. @interface ASBaseViewController ()
  9. @property (nonatomic, strong) UIImageView *leftImgV;
  10. @property (nonatomic, strong) UITextField *searchTf;
  11. @property (nonatomic, strong) UIButton *tfBt;
  12. @property (nonatomic, copy) btnClickBlock tapSearchBlock;
  13. @property (nonatomic, strong) UIView *nav_bottomLineV;
  14. @end
  15. @implementation ASBaseViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self addBaseNav];
  19. self.navigationController.navigationBar.hidden = true;
  20. self.view.backgroundColor = _F8F8F8;
  21. }
  22. - (void)ucHomeStyle:(btnClickBlock)tapSearch {
  23. self.statusBgV.backgroundColor = Col_FFF;
  24. self.customNavBar.backgroundColor = Col_FFF;
  25. self.tapSearchBlock = tapSearch;
  26. [self.customNavBar addSubview:self.leftImgV];
  27. [self.customNavBar addSubview:self.searchTf];
  28. [self.customNavBar addSubview:self.tfBt];
  29. [self.leftImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.leading.equalTo(self.customNavBar).offset(20);
  31. make.width.equalTo(@140);
  32. make.height.equalTo(@43.5);
  33. make.centerY.equalTo(self.customNavBar);
  34. }];
  35. [self.searchTf mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.leading.equalTo(self.leftImgV.mas_trailing).offset(20);
  37. make.height.equalTo(@36);
  38. make.centerY.equalTo(self.leftImgV);
  39. make.trailing.equalTo(self.customNavBar).offset(-10);
  40. }];
  41. [self.tfBt mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.edges.equalTo(self.searchTf);
  43. }];
  44. }
  45. - (void)addBaseNav {
  46. [self.view addSubview:self.statusBgV];
  47. [self.view addSubview:self.customNavBar];
  48. [self.customNavBar addSubview:self.nav_bottomLineV];
  49. self.statusBgV.frame = CGRectMake(0, 0, KScreenWidth, kStatusBarH);
  50. self.customNavBar.frame = CGRectMake(0, kStatusBarH, KScreenWidth, kCustomNavBarH);
  51. self.nav_bottomLineV.frame = CGRectMake(0, kCustomNavBarH-1, KScreenWidth, 1);
  52. }
  53. // MARK: - actions
  54. - (void)searchBtAction {
  55. if (self.tapSearchBlock) {
  56. self.tapSearchBlock();
  57. }
  58. }
  59. // MARK: - subVs
  60. - (UIView *)statusBgV {
  61. if (!_statusBgV) {
  62. UIView *v = [UIView baseV];
  63. v.backgroundColor = _32CFB0;
  64. _statusBgV = v;
  65. }
  66. return _statusBgV;
  67. }
  68. - (UIView *)customNavBar {
  69. if (!_customNavBar) {
  70. UIView *v = [UIView baseV];
  71. v.backgroundColor = _32CFB0;
  72. _customNavBar = v;
  73. }
  74. return _customNavBar;
  75. }
  76. - (UIView *)nav_bottomLineV {
  77. if (!_nav_bottomLineV) {
  78. UIView *v = [UIView baseV];
  79. v.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.05];
  80. _nav_bottomLineV = v;
  81. }
  82. return _nav_bottomLineV;
  83. }
  84. - (UIImageView *)leftImgV {
  85. if (!_leftImgV) {
  86. UIImageView *v = [UIImageView baseImgV];
  87. v.image = [UIImage imageNamed:@"nav_icon"];
  88. _leftImgV = v;
  89. }
  90. return _leftImgV;
  91. }
  92. - (UITextField *)searchTf {
  93. if (!_searchTf) {
  94. UITextField *tf = [[UITextField alloc] init];
  95. tf.borderStyle = UITextBorderStyleNone;
  96. UIView *leftV = [[UIView alloc] init];
  97. leftV.backgroundColor = UIColor.clearColor;
  98. UIImageView *imgV = [UIImageView baseImgV];
  99. imgV.backgroundColor = UIColor.clearColor;
  100. imgV.image = [UIImage imageNamed:@"nav_search"];
  101. leftV.frame = CGRectMake(0, 0, 44, 36);
  102. imgV.frame = CGRectMake(10, 6, 24, 24);
  103. [leftV addSubview:imgV];
  104. tf.leftView = leftV;
  105. tf.leftViewMode = UITextFieldViewModeAlways;
  106. tf.backgroundColor = _F5F5F5;
  107. tf.layer.cornerRadius = 5;
  108. tf.layer.masksToBounds = true;
  109. _searchTf = tf;
  110. }
  111. return _searchTf;
  112. }
  113. - (UIButton *)tfBt {
  114. if (!_tfBt) {
  115. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  116. [bt addTarget:self action:@selector(searchBtAction) forControlEvents:UIControlEventTouchUpInside];
  117. _tfBt = bt;
  118. }
  119. return _tfBt;
  120. }
  121. @end