ASBaseViewController.m 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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) UIButton *backBt;
  14. @property (nonatomic, strong) UIButton *searchNavBt;
  15. @property (nonatomic, copy) btnClickBlock nav_searchBlock;
  16. @property (nonatomic, strong) UIView *emptyV;
  17. @property (nonatomic, strong) UIView *emptylb;
  18. @end
  19. @implementation ASBaseViewController
  20. - (void)setTitleStr:(NSString *)titleStr {
  21. _titleStr = titleStr;
  22. self.nav_titleLB.text = _titleStr;
  23. }
  24. - (void)hiddenEmpty {
  25. self.emptyV.hidden = true;
  26. }
  27. - (void)showEmptyV:(UIView *)v {
  28. if (self.emptyV.superview != nil) {
  29. self.emptyV.hidden = false;
  30. [self.emptyV.superview bringSubviewToFront:self.emptyV];
  31. return;
  32. }
  33. if (v == nil) {
  34. [self.view addSubview:self.emptyV];
  35. [self.emptyV mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.top.equalTo(self.customNavBar.mas_bottom);
  37. make.leading.trailing.bottom.equalTo(self.view);
  38. }];
  39. } else {
  40. [v addSubview:self.emptyV];
  41. [self.emptyV mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.edges.equalTo(v);
  43. make.width.height.equalTo(v);
  44. }];
  45. }
  46. self.emptyV.hidden = false;
  47. [self.emptyV.superview bringSubviewToFront:self.emptyV];
  48. dispatch_async(dispatch_get_main_queue(), ^{
  49. [UIView viewAddHorColorBg:self.emptyV colorArr:@[
  50. (id)_E0FFF5.CGColor,
  51. (id)Col_FFF.CGColor
  52. ] startP:CGPointMake(0.5, 0.25) endP:CGPointMake(0.5, 1)];
  53. [self.emptyV bringSubviewToFront:self.emptylb];
  54. });
  55. }
  56. - (void)viewDidLoad {
  57. [super viewDidLoad];
  58. [self addBaseNav];
  59. self.navigationController.navigationBar.hidden = true;
  60. self.customNavBar.backgroundColor = Col_FFF;
  61. self.view.backgroundColor = _F8F8F8;
  62. }
  63. - (void)viewWillAppear:(BOOL)animated {
  64. [super viewWillAppear:animated];
  65. self.tabBarController.tabBar.hidden = self.navigationController.viewControllers.count > 1;
  66. }
  67. - (void)viewWillDisappear:(BOOL)animated {
  68. [super viewWillAppear:animated];
  69. }
  70. - (void)setNavRightSearch:(btnClickBlock)nav_searchAction {
  71. self.nav_searchBlock = nav_searchAction;
  72. [self.customNavBar addSubview:self.searchNavBt];
  73. [self.searchNavBt mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.width.height.equalTo(@44);
  75. make.trailing.equalTo(self.customNavBar).offset(-10);
  76. make.centerY.equalTo(self.customNavBar);
  77. }];
  78. }
  79. - (void)ucHomeStyle:(btnClickBlock)tapSearch {
  80. self.tapSearchBlock = tapSearch;
  81. [self.customNavBar addSubview:self.leftImgV];
  82. [self.customNavBar addSubview:self.searchTf];
  83. [self.customNavBar addSubview:self.tfBt];
  84. [self.leftImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.leading.equalTo(self.customNavBar).offset(20);
  86. make.width.equalTo(@140);
  87. make.height.equalTo(@43.5);
  88. make.centerY.equalTo(self.customNavBar);
  89. }];
  90. [self.searchTf mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.leading.equalTo(self.leftImgV.mas_trailing).offset(20);
  92. make.height.equalTo(@36);
  93. make.centerY.equalTo(self.leftImgV);
  94. make.trailing.equalTo(self.customNavBar).offset(-10);
  95. }];
  96. [self.tfBt mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.edges.equalTo(self.searchTf);
  98. }];
  99. }
  100. - (void)addBaseNav {
  101. [self.view addSubview:self.statusBgV];
  102. [self.view addSubview:self.customNavBar];
  103. [self.customNavBar addSubview:self.nav_bottomLineV];
  104. self.statusBgV.frame = CGRectMake(0, 0, KScreenWidth, kStatusBarH);
  105. self.customNavBar.frame = CGRectMake(0, kStatusBarH, KScreenWidth, kCustomNavBarH);
  106. self.nav_bottomLineV.frame = CGRectMake(0, kCustomNavBarH-1, KScreenWidth, 1);
  107. [self.customNavBar addSubview:self.backBt];
  108. [self.customNavBar addSubview:self.nav_titleLB];
  109. [self.backBt mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.leading.equalTo(self.customNavBar).offset(10);
  111. make.centerY.equalTo(self.customNavBar);
  112. make.width.height.equalTo(@44);
  113. }];
  114. [self.nav_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.center.equalTo(self.customNavBar);
  116. make.width.equalTo(self.customNavBar).offset(-120);
  117. make.height.equalTo(@40);
  118. }];
  119. self.backBt.hidden = true;
  120. if (self.navigationController.viewControllers.count > 1) {
  121. self.backBt.hidden = false;
  122. }
  123. [self.emptyV addSubview:self.emptylb];
  124. [self.emptylb mas_makeConstraints:^(MASConstraintMaker *make) {
  125. make.leading.equalTo(self.emptyV).offset(30);
  126. make.trailing.equalTo(self.emptyV).offset(-30);
  127. make.centerY.equalTo(self.emptyV).offset(-30);
  128. make.top.greaterThanOrEqualTo(self.emptyV).offset(20);
  129. }];
  130. }
  131. // MARK: - actions
  132. - (void)searchBtAction {
  133. UIViewController *vc = [CTMediator.sharedInstance getSearchVc:@{}];
  134. [self presentViewController:vc animated:true completion:nil];
  135. if (self.tapSearchBlock) {
  136. self.tapSearchBlock();
  137. }
  138. }
  139. // MARK: - subVs
  140. - (UIView *)emptyV {
  141. if (!_emptyV) {
  142. UIView *v = [UIView baseV];
  143. v.backgroundColor = Col_FFF;
  144. v.hidden = true;
  145. _emptyV = v;
  146. }
  147. return _emptyV;
  148. }
  149. - (UIView *)emptylb {
  150. if (!_emptylb) {
  151. UILabel *lb = [UILabel baseLb];
  152. lb.font = [UIFont fontWithName:Rob_Medium size:72];
  153. lb.textAlignment = NSTextAlignmentCenter;
  154. lb.numberOfLines = 0;
  155. lb.text = @"No Data";
  156. lb.textColor = _043632;
  157. _emptylb = lb;
  158. }
  159. return _emptylb;
  160. }
  161. - (UIView *)statusBgV {
  162. if (!_statusBgV) {
  163. UIView *v = [UIView baseV];
  164. v.backgroundColor = _32CFB0;
  165. _statusBgV = v;
  166. }
  167. return _statusBgV;
  168. }
  169. - (UIView *)customNavBar {
  170. if (!_customNavBar) {
  171. UIView *v = [UIView baseV];
  172. v.backgroundColor = _32CFB0;
  173. _customNavBar = v;
  174. }
  175. return _customNavBar;
  176. }
  177. - (UIView *)nav_bottomLineV {
  178. if (!_nav_bottomLineV) {
  179. UIView *v = [UIView baseV];
  180. v.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.05];
  181. _nav_bottomLineV = v;
  182. }
  183. return _nav_bottomLineV;
  184. }
  185. - (UIImageView *)leftImgV {
  186. if (!_leftImgV) {
  187. UIImageView *v = [UIImageView baseImgV];
  188. v.image = [UIImage imageNamed:@"nav_icon"];
  189. _leftImgV = v;
  190. }
  191. return _leftImgV;
  192. }
  193. - (UITextField *)searchTf {
  194. if (!_searchTf) {
  195. UITextField *tf = [[UITextField alloc] init];
  196. tf.borderStyle = UITextBorderStyleNone;
  197. UIView *leftV = [[UIView alloc] init];
  198. leftV.backgroundColor = UIColor.clearColor;
  199. UIImageView *imgV = [UIImageView baseImgV];
  200. imgV.backgroundColor = UIColor.clearColor;
  201. imgV.image = [UIImage imageNamed:@"nav_search"];
  202. leftV.frame = CGRectMake(0, 0, 44, 36);
  203. imgV.frame = CGRectMake(10, 6, 24, 24);
  204. [leftV addSubview:imgV];
  205. tf.leftView = leftV;
  206. tf.leftViewMode = UITextFieldViewModeAlways;
  207. tf.backgroundColor = _F5F5F5;
  208. tf.layer.cornerRadius = 5;
  209. tf.layer.masksToBounds = true;
  210. _searchTf = tf;
  211. }
  212. return _searchTf;
  213. }
  214. - (UIButton *)tfBt {
  215. if (!_tfBt) {
  216. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  217. [bt addTarget:self action:@selector(searchBtAction) forControlEvents:UIControlEventTouchUpInside];
  218. _tfBt = bt;
  219. }
  220. return _tfBt;
  221. }
  222. - (UIButton *)backBt {
  223. if (!_backBt) {
  224. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  225. [bt setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
  226. [bt addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  227. _backBt = bt;
  228. }
  229. return _backBt;
  230. }
  231. - (UILabel *)nav_titleLB {
  232. if (!_nav_titleLB) {
  233. UILabel *lb = [[UILabel alloc] init];
  234. lb.font = [UIFont fontWithName:Rob_Regular size:20];
  235. lb.textAlignment = NSTextAlignmentCenter;
  236. lb.textColor = Col_000;
  237. _nav_titleLB = lb;
  238. }
  239. return _nav_titleLB;
  240. }
  241. - (void)backAction {
  242. [self.navigationController popViewControllerAnimated:true];
  243. }
  244. - (UIButton *)searchNavBt {
  245. if (!_searchNavBt) {
  246. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  247. [bt setImage:[UIImage imageNamed:@"nav_search"] forState:UIControlStateNormal];
  248. [bt addTarget:self action:@selector(search_navAction) forControlEvents:UIControlEventTouchUpInside];
  249. _searchNavBt = bt;
  250. }
  251. return _searchNavBt;
  252. }
  253. // MARK: - actions
  254. - (void)search_navAction {
  255. UIViewController *vc = [CTMediator.sharedInstance getSearchVc:@{}];
  256. [self presentViewController:vc animated:true completion:nil];
  257. if (self.nav_searchBlock) {
  258. self.nav_searchBlock();
  259. }
  260. }
  261. @end