SearchViewController.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. // SearchViewController.m
  2. // AICity
  3. //
  4. // Created by 刘伟伟 on 2023/7/8.
  5. // Copyright © 2023 wei.z. All rights reserved.
  6. //
  7. #import "SearchViewController.h"
  8. #import "UICollectionViewLeftAlignedLayout.h"
  9. #import "SearchCommonBarView.h"
  10. #import "SearchResultViewController.h"
  11. #import "ZFNormalViewController.h"
  12. @interface SearchViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
  13. @property(nonatomic,strong)SearchCommonBarView *barView;
  14. @property(nonatomic,strong)UICollectionView *collect;
  15. @property(nonatomic,strong)NSMutableArray *searchList;
  16. @property(nonatomic,strong)NSArray *hotkeyDataArr;
  17. @property(nonatomic,strong)NSArray *hotMoviesArr;
  18. @property(nonatomic,strong)NSArray *searchResArr;
  19. @property(nonatomic,assign)int vid;
  20. @end
  21. @implementation SearchViewController
  22. -(void)viewWillAppear:(BOOL)animated{
  23. [super viewWillAppear:animated];
  24. self.searchList = [NSMutableArray array];
  25. id arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"mylocationhistory"];
  26. if([arr isKindOfClass:[NSArray class]] && [(NSArray *)arr count] > 0){
  27. [self.searchList addObjectsFromArray:(NSArray *)arr];
  28. }
  29. [self.collect reloadData];
  30. // UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(endEd)];
  31. // [self.view addGestureRecognizer:g];
  32. }
  33. //-(void)endEd{
  34. // [self.view endEditing:true];
  35. //}
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. self.fd_prefersNavigationBarHidden = true;
  39. self.searchList = [NSMutableArray array];
  40. id arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"mylocationhistory"];
  41. if([arr isKindOfClass:[NSArray class]] && [(NSArray *)arr count] > 0){
  42. [self.searchList addObjectsFromArray:(NSArray *)arr];
  43. }
  44. // Do any additional setup after loading the view.
  45. [self.view addSubview:self.barView];
  46. // [self.barView mas_makeConstraints:^(MASConstraintMaker *make) {
  47. // make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 48));
  48. // make.left.equalTo(self.view);
  49. // make.top.equalTo(self.view).offset(NAV_HEIGHT);
  50. // }];
  51. [self.view addSubview:self.collect];
  52. [self.collect mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.top.equalTo(self.barView.mas_bottom);
  54. make.left.right.bottom.equalTo(self.view);
  55. }];
  56. [self requestData];
  57. }
  58. -(UIStatusBarStyle)preferredStatusBarStyle{
  59. return UIStatusBarStyleLightContent;
  60. }
  61. -(void)requestData{
  62. //热门关键字
  63. [RequestTool post:@"search/getHotSearchKey" params:@{@"count":@(8)} success:^(id responseObject) {
  64. NSLog(@"home/getHotSearchKey-%@",responseObject);
  65. if([responseObject[@"code"] intValue] == 0){
  66. id hotKeys = responseObject[@"data"][@"hot_keys"];
  67. if([hotKeys isKindOfClass:[NSArray class]]){
  68. self.hotkeyDataArr = hotKeys;
  69. }else{
  70. self.hotkeyDataArr = @[];
  71. }
  72. }else{
  73. self.hotkeyDataArr = @[];
  74. }
  75. [self.collect reloadData];
  76. } failure:^(NSError *error) {
  77. self.hotkeyDataArr = @[];
  78. [self.collect reloadData];
  79. }];
  80. //热搜影片
  81. [RequestTool post:@"search/getHotSearchMovies" params:@{@"page":@{@"page":@(1),@"pageSize":@(10)}} success:^(id responseObject) {
  82. NSLog(@"home/homePage-%@",responseObject);
  83. if([responseObject[@"code"] intValue] == 0){
  84. id movies = responseObject[@"data"][@"list"];
  85. if([movies isKindOfClass:[NSArray class]]){
  86. self.hotMoviesArr = movies;
  87. }else{
  88. self.hotMoviesArr = @[];
  89. }
  90. }else{
  91. self.hotMoviesArr = @[];
  92. }
  93. [self.collect reloadData];
  94. } failure:^(NSError *error) {
  95. self.hotMoviesArr = @[];
  96. [self.collect reloadData];
  97. }];
  98. }
  99. -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
  100. [self.view endEditing:YES];
  101. }
  102. -(void)search:(NSString *)keyword{
  103. [self.view endEditing:true];
  104. if(![self.searchList containsObject:keyword]){
  105. [self.searchList addObject:keyword];
  106. [[NSUserDefaults standardUserDefaults] setObject:self.searchList forKey:@"mylocationhistory"];
  107. }
  108. [self.collect reloadData];
  109. //搜索影片
  110. // __weak typeof(self) weakSelf = self;
  111. // [RequestTool post:@"search/searchMovie" params:@{@"search_key":keyword,@"page":@{@"page":@(1),@"pageSize":@(10)}} success:^(id responseObject) {
  112. // NSLog(@"home/homePage-%@",responseObject);
  113. // if([responseObject[@"code"] intValue] == 0){
  114. // weakSelf.searchResArr = responseObject[@"data"][@"list"];
  115. // SearchResultViewController *vc = [SearchResultViewController new];
  116. // vc.searchResArr = weakSelf.searchResArr;
  117. // vc.txt = keyword;
  118. // vc.hidesBottomBarWhenPushed = true;
  119. // [weakSelf.navigationController pushViewController:vc animated:true];
  120. // }
  121. // } failure:^(NSError *error) {}];
  122. SearchResultViewController *vc = [SearchResultViewController new];
  123. vc.txt = keyword;
  124. vc.hidesBottomBarWhenPushed = true;
  125. [self.navigationController pushViewController:vc animated:true];
  126. }
  127. -(void)playItem{
  128. ZFNormalViewController *vc = [[ZFNormalViewController alloc] init];
  129. vc.vid = self.vid;
  130. vc.hidesBottomBarWhenPushed = true;
  131. [self.navigationController pushViewController:vc animated:true];
  132. }
  133. #pragma mark -- collicationdelegate
  134. //返回分区个数
  135. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  136. return 1;
  137. }
  138. //返回每个分区的item个数
  139. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  140. if(self.searchList.count>0){
  141. return 3+self.searchList.count;
  142. }else{
  143. return 2;
  144. }
  145. }
  146. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  147. __weak typeof (self) weakSelf = self;
  148. if(self.searchList.count>0){
  149. if(indexPath.row == 0){
  150. SearchTitCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([SearchTitCell class]) forIndexPath:indexPath];
  151. cell.delBlock = ^{
  152. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"mylocationhistory"];
  153. weakSelf.searchList = [NSMutableArray array];
  154. [weakSelf.collect reloadData];
  155. };
  156. return cell;
  157. }else if(indexPath.row<=self.searchList.count){
  158. SearchItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([SearchItemCell class]) forIndexPath:indexPath];
  159. cell.nameLab.text = self.searchList[indexPath.row - 1];
  160. return cell;
  161. }else if(indexPath.row == self.searchList.count+1){
  162. FoundCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FoundCell class]) forIndexPath:indexPath];
  163. cell.hotkeyDataArr = self.hotkeyDataArr;
  164. cell.tapBlock = ^(NSString * _Nonnull str) {
  165. [weakSelf search:str];
  166. };
  167. return cell;
  168. }else{
  169. HotSearchCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([HotSearchCell class]) forIndexPath:indexPath];
  170. cell.hotMoviesArr = self.hotMoviesArr;
  171. cell.tapBlock = ^(int vid) {
  172. weakSelf.vid = vid;
  173. [weakSelf playItem];
  174. };
  175. return cell;
  176. }
  177. }else{
  178. if(indexPath.row == 0){
  179. FoundCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FoundCell class]) forIndexPath:indexPath];
  180. cell.hotkeyDataArr = self.hotkeyDataArr;
  181. cell.tapBlock = ^(NSString * _Nonnull str) {
  182. [weakSelf search:str];
  183. };
  184. return cell;
  185. }else{
  186. HotSearchCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([HotSearchCell class]) forIndexPath:indexPath];
  187. cell.hotMoviesArr = self.hotMoviesArr;
  188. cell.tapBlock = ^(int vid) {
  189. weakSelf.vid = vid;
  190. [weakSelf playItem];
  191. };
  192. return cell;
  193. }
  194. }
  195. }
  196. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  197. if(self.searchList.count>0){
  198. if(indexPath.row == 0){
  199. //do nothing
  200. }else if(indexPath.row<=self.searchList.count){
  201. [self search:self.searchList[indexPath.row - 1]];
  202. }
  203. }
  204. }
  205. #pragma mark - UICollectionViewDelegateFlowLayout
  206. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  207. if(self.searchList.count>0){
  208. if(indexPath.row == 0){
  209. return CGSizeMake(SCREEN_WIDTH-24, 37);
  210. }else if(indexPath.row<=self.searchList.count){
  211. NSString *str=self.searchList[indexPath.row-1];
  212. return CGSizeMake(str.length*12+25, 30);
  213. }else if(indexPath.row == self.searchList.count+1){
  214. return CGSizeMake(SCREEN_WIDTH-24, 160);
  215. }else{
  216. return CGSizeMake(SCREEN_WIDTH-24, 415+58*4);
  217. }
  218. }else{
  219. if(indexPath.row == 0){
  220. return CGSizeMake(SCREEN_WIDTH-24, 160);
  221. }else{
  222. return CGSizeMake(SCREEN_WIDTH-24, 415+58*4);
  223. }
  224. }
  225. }
  226. - (UICollectionView *)collect {
  227. if (!_collect) {
  228. UICollectionViewLeftAlignedLayout *layout = [[UICollectionViewLeftAlignedLayout alloc] init];
  229. layout.minimumLineSpacing = 8; //跟滚动方向相同的间距
  230. layout.minimumInteritemSpacing = 8; //跟滚动方向垂直的间距
  231. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  232. _collect = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH-60, 110) collectionViewLayout:layout];
  233. _collect.contentInset = UIEdgeInsetsMake(0, 12, 12, 12);
  234. //注册cell
  235. [_collect registerClass:[SearchTitCell class] forCellWithReuseIdentifier:@"SearchTitCell"];
  236. [_collect registerClass:[SearchItemCell class] forCellWithReuseIdentifier:@"SearchItemCell"];
  237. [_collect registerClass:[FoundCell class] forCellWithReuseIdentifier:@"FoundCell"];
  238. [_collect registerClass:[HotSearchCell class] forCellWithReuseIdentifier:@"HotSearchCell"];
  239. _collect.dataSource = self;
  240. _collect.delegate = self;
  241. _collect.backgroundColor = rgba(18, 23, 41, 1);
  242. }
  243. return _collect;
  244. }
  245. -(SearchCommonBarView *)barView{
  246. if(!_barView){
  247. CGFloat h=0;
  248. if(@available(iOS 13.0, *)){
  249. UIStatusBarManager *sc= [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager;
  250. CGRect f=sc.statusBarFrame;
  251. h=f.size.height;
  252. }else{
  253. h=[UIApplication sharedApplication].statusBarFrame.size.height;
  254. }
  255. if(h>=40){
  256. h=30;
  257. }
  258. _barView =[[SearchCommonBarView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 72-20+h)];
  259. _barView.backgroundColor = rgba(18, 23, 41, 1);
  260. __weak typeof(self) weakSelf = self;
  261. _barView.searchAction = ^(NSString * _Nonnull tit) {
  262. [weakSelf search:tit];
  263. };
  264. }
  265. return _barView;
  266. }
  267. @end
  268. #pragma mark -- SearchTitCell
  269. @interface SearchTitCell()
  270. @end
  271. @implementation SearchTitCell
  272. - (instancetype)initWithFrame:(CGRect)frame
  273. {
  274. self = [super initWithFrame:frame];
  275. if (self) {
  276. [self setUp];
  277. }
  278. return self;
  279. }
  280. -(void)delAction{
  281. if(self.delBlock){
  282. self.delBlock();
  283. }
  284. }
  285. - (void)setUp {
  286. self.backgroundColor = [UIColor clearColor];
  287. UILabel *nameLab = [UILabel new];
  288. nameLab.text = @"搜索记录";
  289. nameLab.font = [UIFont boldSystemFontOfSize:16];
  290. nameLab.textColor = [UIColor whiteColor];
  291. [self.contentView addSubview:nameLab];
  292. [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
  293. make.left.equalTo(self.contentView).offset(0);
  294. make.bottom.equalTo(self.contentView).offset(-4);
  295. }];
  296. UIImageView *iv = [UIImageView new];
  297. iv.image = [UIImage imageNamed:@"Frame90"];
  298. iv.userInteractionEnabled = true;
  299. UITapGestureRecognizer *g=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(delAction)];
  300. [iv addGestureRecognizer:g];
  301. [self.contentView addSubview:iv];
  302. [iv mas_makeConstraints:^(MASConstraintMaker *make) {
  303. make.right.equalTo(self.contentView).offset(0);
  304. make.centerY.equalTo(nameLab);
  305. }];
  306. }
  307. @end
  308. @implementation SearchItemCell
  309. - (instancetype)initWithFrame:(CGRect)frame
  310. {
  311. self = [super initWithFrame:frame];
  312. if (self) {
  313. [self setUp];
  314. }
  315. return self;
  316. }
  317. - (void)setUp {
  318. self.backgroundColor = [UIColor clearColor];
  319. UIView *bgView =[UIView new];
  320. bgView.backgroundColor = rgba(52, 56, 68, 1);
  321. [self.contentView addSubview:bgView];
  322. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  323. make.edges.equalTo(self.contentView);
  324. }];
  325. UILabel *nameLab = [UILabel new];
  326. self.nameLab = nameLab;
  327. nameLab.text = @"流浪地球";
  328. nameLab.font = [UIFont boldSystemFontOfSize:12];
  329. nameLab.textColor = rgba(255, 255, 255, 0.8);
  330. [bgView addSubview:nameLab];
  331. [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
  332. make.center.equalTo(bgView);
  333. }];
  334. bgView.layer.cornerRadius = 16;
  335. bgView.layer.masksToBounds = true;
  336. }
  337. @end
  338. @interface FoundCell()
  339. @property(nonatomic,strong)NSArray *nameArr;
  340. @property(nonatomic,strong)NSArray *arr;
  341. @end
  342. @implementation FoundCell
  343. - (instancetype)initWithFrame:(CGRect)frame
  344. {
  345. self = [super initWithFrame:frame];
  346. if (self) {
  347. [self setUp];
  348. }
  349. return self;
  350. }
  351. -(void)setHotkeyDataArr:(NSArray *)hotkeyDataArr{
  352. if(![hotkeyDataArr isKindOfClass:[NSArray class]]){
  353. hotkeyDataArr = @[];
  354. }
  355. _hotkeyDataArr = hotkeyDataArr;
  356. NSMutableArray *arr = [NSMutableArray array];
  357. self.arr = arr;
  358. if(hotkeyDataArr.count){
  359. [arr addObjectsFromArray:hotkeyDataArr];
  360. }
  361. if(self.nameArr.count){
  362. [arr addObjectsFromArray:self.nameArr];
  363. }
  364. // if(hotkeyDataArr.count<8){
  365. // [arr addObjectsFromArray:hotkeyDataArr];
  366. // [arr addObjectsFromArray:self.nameArr];
  367. // self.nameArr = arr;
  368. // }else{
  369. // self.nameArr = hotkeyDataArr;
  370. // [arr addObjectsFromArray:hotkeyDataArr];
  371. // }
  372. for(int i = 0;i<8;i++){
  373. UILabel *item = [self.contentView viewWithTag:100+i];
  374. BOOL shouldHide = i>=arr.count;
  375. item.hidden = shouldHide;
  376. if(shouldHide){
  377. item.attributedText = nil;
  378. item.text = @"";
  379. continue;
  380. }
  381. if(i<3){
  382. NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d",i+1] attributes:@{NSForegroundColorAttributeName:rgba(255, 212, 0, 1),
  383. NSFontAttributeName:[UIFont boldSystemFontOfSize:14]}];
  384. NSString *str=[NSString stringWithFormat:@" %@",arr[i]];
  385. NSMutableAttributedString *attrString2 = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],
  386. NSFontAttributeName:[UIFont boldSystemFontOfSize:14]}];
  387. [attrString1 appendAttributedString:attrString2];
  388. item.attributedText = attrString1;
  389. }else{
  390. item.text =[NSString stringWithFormat:@"%d %@",i+1,arr[i]];
  391. }
  392. }
  393. }
  394. -(void)searchAct:(UITapGestureRecognizer *)g{
  395. NSInteger x = g.view.tag - 100;
  396. if(x<0 || x>=self.arr.count){
  397. return;
  398. }
  399. NSString *str = self.arr[x];
  400. if(self.tapBlock){
  401. self.tapBlock(str);
  402. }
  403. }
  404. - (void)setUp {
  405. self.backgroundColor = [UIColor clearColor];
  406. UILabel *nameLab = [UILabel new];
  407. nameLab.text = @"搜索发现";
  408. nameLab.font = [UIFont boldSystemFontOfSize:16];
  409. nameLab.textColor = rgba(255, 212, 0, 1);
  410. [self.contentView addSubview:nameLab];
  411. [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
  412. make.left.equalTo(self.contentView).offset(0);
  413. make.top.equalTo(self.contentView).offset(16);
  414. }];
  415. self.nameArr = @[@"检查风云",@"宇宙探索编辑部",@"昆仑神宫",@"不止不休",@"幕后玩家",@"我的女友们",@"普罗米修斯",@"古董局中局"];
  416. for(int i=0;i<8;i++){
  417. UILabel *item = [UILabel new];
  418. item.tag = 100+i;
  419. UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(searchAct:)];
  420. item.userInteractionEnabled = true;
  421. [item addGestureRecognizer:g];
  422. if(i<3){
  423. NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d",i+1] attributes:@{NSForegroundColorAttributeName:rgba(255, 212, 0, 1),
  424. NSFontAttributeName:[UIFont boldSystemFontOfSize:14]}];
  425. NSMutableAttributedString *attrString2 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",self.nameArr[i]] attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],
  426. NSFontAttributeName:[UIFont systemFontOfSize:14]}];
  427. [attrString1 appendAttributedString:attrString2];
  428. item.attributedText = attrString1;
  429. }else{
  430. item.font = [UIFont boldSystemFontOfSize:14];
  431. item.textColor = [UIColor whiteColor];
  432. item.text =[NSString stringWithFormat:@"%d %@",i+1,self.nameArr[i]];
  433. }
  434. [self.contentView addSubview:item];
  435. [item mas_makeConstraints:^(MASConstraintMaker *make) {
  436. if(i<4){
  437. make.left.equalTo(self.contentView).offset(1);
  438. }else{
  439. make.left.equalTo(self.contentView).offset(180-12);
  440. }
  441. make.top.equalTo(nameLab.mas_bottom).offset(12+30*(i%4));
  442. }];
  443. }
  444. }
  445. @end
  446. @implementation HotSearchCell
  447. - (instancetype)initWithFrame:(CGRect)frame
  448. {
  449. self = [super initWithFrame:frame];
  450. if (self) {
  451. [self setUp];
  452. }
  453. return self;
  454. }
  455. -(void)tapAct:(UITapGestureRecognizer *)g{
  456. NSInteger x = g.view.tag - 200;
  457. if(self.hotMoviesArr.count>x){
  458. int vid = [self.hotMoviesArr[x][@"vid"] intValue];
  459. if(self.tapBlock){
  460. self.tapBlock(vid);
  461. }
  462. }
  463. }
  464. -(void)setHotMoviesArr:(NSArray *)hotMoviesArr{
  465. if(![hotMoviesArr isKindOfClass:[NSArray class]]){
  466. hotMoviesArr = @[];
  467. }
  468. _hotMoviesArr = hotMoviesArr;
  469. UIView *container = [self.contentView viewWithTag:100];
  470. for(int i=0;i<10;i++){
  471. UIView *iv = [container viewWithTag:200+i];
  472. BOOL shouldHide = i >= hotMoviesArr.count;
  473. iv.hidden = shouldHide;
  474. if(shouldHide){
  475. continue;
  476. }
  477. UIImageView *icon = [iv viewWithTag:300];
  478. [icon sd_setImageWithURL:[NSURL URLWithString:hotMoviesArr[i][@"vertical_cover_url"]]];
  479. UILabel *lab1 = [iv viewWithTag:301];
  480. if(i<3){
  481. NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d",i+1] attributes:@{NSForegroundColorAttributeName:rgba(255, 61, 0, 1),
  482. NSFontAttributeName:[UIFont boldSystemFontOfSize:14]}];
  483. NSString *str = [NSString stringWithFormat:@" %@",hotMoviesArr[i][@"ch_name"]];
  484. NSMutableAttributedString *attrString2 = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],
  485. NSFontAttributeName:[UIFont systemFontOfSize:14]}];
  486. [attrString1 appendAttributedString:attrString2];
  487. lab1.attributedText = attrString1;
  488. }else{
  489. lab1.text =[NSString stringWithFormat:@"%d %@",i+1,hotMoviesArr[i][@"ch_name"]];
  490. }
  491. UILabel *lab2 = [iv viewWithTag:302];
  492. // lab2.text = @"2023 / 9.6分 / 剧情 / 美国 / 沈腾";
  493. NSDate* date = [NSDate dateWithTimeIntervalSince1970:[hotMoviesArr[i][@"screen_time"] doubleValue]];
  494. NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
  495. [formatter setDateFormat:@"yyyy"];
  496. NSString* dateString = [formatter stringFromDate:date];
  497. NSString *c = [NSString stringWithFormat:@"%@ / %.1f ",dateString,[hotMoviesArr[i][@"score"] floatValue]];
  498. NSArray *class_list = hotMoviesArr[i][@"class_list"];
  499. if(![class_list isKindOfClass:[NSArray class]]){
  500. class_list = @[];
  501. }
  502. for(int j=0;j<class_list.count;j++){
  503. c = [NSString stringWithFormat:@"%@/ %@ ",c,class_list[j][@"classname"]];
  504. }
  505. c = [NSString stringWithFormat:@"%@ / %@",c,hotMoviesArr[i][@"country"]];
  506. lab2.text = c;
  507. }
  508. }
  509. - (void)setUp {
  510. self.backgroundColor = [UIColor clearColor];
  511. UIView *bg = [UIView new];
  512. bg.backgroundColor = rgba(52, 56, 68, 1);
  513. bg.tag = 100;
  514. [self.contentView addSubview:bg];
  515. [bg mas_makeConstraints:^(MASConstraintMaker *make) {
  516. make.top.equalTo(self.contentView).offset(16);
  517. make.left.equalTo(self.contentView).offset(0);
  518. make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-24, 400+58*4));
  519. }];
  520. UILabel *tit = [UILabel new];
  521. NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:@"热搜" attributes:@{NSForegroundColorAttributeName:rgba(255, 61, 0, 1),
  522. NSFontAttributeName:[UIFont boldSystemFontOfSize:16]}];
  523. NSMutableAttributedString *attrString2 = [[NSMutableAttributedString alloc] initWithString:@"Hot" attributes:@{NSForegroundColorAttributeName:rgba(255, 212, 0, 1),
  524. NSFontAttributeName:[UIFont boldSystemFontOfSize:12]}];
  525. [attrString1 appendAttributedString:attrString2];
  526. tit.attributedText = attrString1;
  527. [bg addSubview:tit];
  528. [tit mas_makeConstraints:^(MASConstraintMaker *make) {
  529. make.top.equalTo(bg).offset(16);
  530. make.left.equalTo(bg).offset(12);
  531. }];
  532. for(int i=0;i<10;i++){
  533. UIView *iv = [UIView new];
  534. // iv.backgroundColor = [UIColor grayColor];
  535. iv.tag = 200+i;
  536. UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAct:)];
  537. [iv addGestureRecognizer:g];
  538. [bg addSubview:iv];
  539. [iv mas_makeConstraints:^(MASConstraintMaker *make) {
  540. make.top.equalTo(tit.mas_bottom).offset(12+58*i);
  541. make.left.right.equalTo(bg);
  542. make.height.mas_equalTo(@46);
  543. }];
  544. UIImageView *icon = [UIImageView new];
  545. icon.image = [UIImage imageNamed:@""];
  546. // icon.backgroundColor = [UIColor redColor];
  547. icon.tag = 300;
  548. [iv addSubview:icon];
  549. [icon mas_makeConstraints:^(MASConstraintMaker *make) {
  550. make.top.equalTo(iv);
  551. make.left.equalTo(iv).offset(12);
  552. make.size.mas_equalTo(CGSizeMake(35, 46));
  553. }];
  554. UILabel *lab1 = [UILabel new];
  555. lab1.tag = 301;
  556. if(i<3){
  557. NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d",i+1] attributes:@{NSForegroundColorAttributeName:rgba(255, 61, 0, 1),
  558. NSFontAttributeName:[UIFont boldSystemFontOfSize:14]}];
  559. NSMutableAttributedString *attrString2 = [[NSMutableAttributedString alloc] initWithString:@" 检查风云" attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],
  560. NSFontAttributeName:[UIFont systemFontOfSize:14]}];
  561. [attrString1 appendAttributedString:attrString2];
  562. lab1.attributedText = attrString1;
  563. }else{
  564. lab1.font = [UIFont systemFontOfSize:14];
  565. lab1.textColor = [UIColor whiteColor];
  566. lab1.text =[NSString stringWithFormat:@"%d %@",i+1,@" 检查风云"];
  567. }
  568. [iv addSubview:lab1];
  569. [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
  570. make.left.equalTo(icon.mas_right).offset(9);
  571. make.top.equalTo(icon).offset(3);
  572. }];
  573. UILabel *lab2 = [UILabel new];
  574. lab2.tag = 302;
  575. lab2.text = @"2023 / 9.6分 / 剧情 / 美国 / 沈腾";
  576. lab2.textColor = rgba(255, 255, 255, 0.4);
  577. lab2.font=[UIFont systemFontOfSize:12];
  578. [iv addSubview:lab2];
  579. [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
  580. make.left.equalTo(lab1);
  581. make.top.equalTo(lab1.mas_bottom).offset(6);
  582. }];
  583. icon.layer.cornerRadius = 6;
  584. icon.layer.masksToBounds = true;
  585. }
  586. bg.layer.cornerRadius = 12;
  587. bg.layer.masksToBounds = true;
  588. }
  589. @end