| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629 |
- // SearchViewController.m
- // AICity
- //
- // Created by 刘伟伟 on 2023/7/8.
- // Copyright © 2023 wei.z. All rights reserved.
- //
- #import "SearchViewController.h"
- #import "UICollectionViewLeftAlignedLayout.h"
- #import "SearchCommonBarView.h"
- #import "SearchResultViewController.h"
- #import "ZFNormalViewController.h"
- @interface SearchViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
- @property(nonatomic,strong)SearchCommonBarView *barView;
- @property(nonatomic,strong)UICollectionView *collect;
- @property(nonatomic,strong)NSMutableArray *searchList;
- @property(nonatomic,strong)NSArray *hotkeyDataArr;
- @property(nonatomic,strong)NSArray *hotMoviesArr;
- @property(nonatomic,strong)NSArray *searchResArr;
- @property(nonatomic,assign)int vid;
- @end
- @implementation SearchViewController
- -(void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- self.searchList = [NSMutableArray array];
- id arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"mylocationhistory"];
- if([arr isKindOfClass:[NSArray class]] && [(NSArray *)arr count] > 0){
- [self.searchList addObjectsFromArray:(NSArray *)arr];
- }
- [self.collect reloadData];
- // UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(endEd)];
- // [self.view addGestureRecognizer:g];
- }
- //-(void)endEd{
- // [self.view endEditing:true];
- //}
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.fd_prefersNavigationBarHidden = true;
- self.searchList = [NSMutableArray array];
- id arr = [[NSUserDefaults standardUserDefaults] objectForKey:@"mylocationhistory"];
- if([arr isKindOfClass:[NSArray class]] && [(NSArray *)arr count] > 0){
- [self.searchList addObjectsFromArray:(NSArray *)arr];
- }
-
- // Do any additional setup after loading the view.
- [self.view addSubview:self.barView];
- // [self.barView mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 48));
- // make.left.equalTo(self.view);
- // make.top.equalTo(self.view).offset(NAV_HEIGHT);
- // }];
- [self.view addSubview:self.collect];
- [self.collect mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.barView.mas_bottom);
- make.left.right.bottom.equalTo(self.view);
- }];
- [self requestData];
- }
- -(UIStatusBarStyle)preferredStatusBarStyle{
- return UIStatusBarStyleLightContent;
- }
- -(void)requestData{
- //热门关键字
- [RequestTool post:@"search/getHotSearchKey" params:@{@"count":@(8)} success:^(id responseObject) {
- NSLog(@"home/getHotSearchKey-%@",responseObject);
- if([responseObject[@"code"] intValue] == 0){
- id hotKeys = responseObject[@"data"][@"hot_keys"];
- if([hotKeys isKindOfClass:[NSArray class]]){
- self.hotkeyDataArr = hotKeys;
- }else{
- self.hotkeyDataArr = @[];
- }
- }else{
- self.hotkeyDataArr = @[];
- }
- [self.collect reloadData];
- } failure:^(NSError *error) {
- self.hotkeyDataArr = @[];
- [self.collect reloadData];
- }];
- //热搜影片
- [RequestTool post:@"search/getHotSearchMovies" params:@{@"page":@{@"page":@(1),@"pageSize":@(10)}} success:^(id responseObject) {
- NSLog(@"home/homePage-%@",responseObject);
- if([responseObject[@"code"] intValue] == 0){
- id movies = responseObject[@"data"][@"list"];
- if([movies isKindOfClass:[NSArray class]]){
- self.hotMoviesArr = movies;
- }else{
- self.hotMoviesArr = @[];
- }
- }else{
- self.hotMoviesArr = @[];
- }
- [self.collect reloadData];
- } failure:^(NSError *error) {
- self.hotMoviesArr = @[];
- [self.collect reloadData];
- }];
-
-
- }
- -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
- [self.view endEditing:YES];
- }
- -(void)search:(NSString *)keyword{
- [self.view endEditing:true];
- if(![self.searchList containsObject:keyword]){
- [self.searchList addObject:keyword];
- [[NSUserDefaults standardUserDefaults] setObject:self.searchList forKey:@"mylocationhistory"];
- }
- [self.collect reloadData];
- //搜索影片
- // __weak typeof(self) weakSelf = self;
- // [RequestTool post:@"search/searchMovie" params:@{@"search_key":keyword,@"page":@{@"page":@(1),@"pageSize":@(10)}} success:^(id responseObject) {
- // NSLog(@"home/homePage-%@",responseObject);
- // if([responseObject[@"code"] intValue] == 0){
- // weakSelf.searchResArr = responseObject[@"data"][@"list"];
- // SearchResultViewController *vc = [SearchResultViewController new];
- // vc.searchResArr = weakSelf.searchResArr;
- // vc.txt = keyword;
- // vc.hidesBottomBarWhenPushed = true;
- // [weakSelf.navigationController pushViewController:vc animated:true];
- // }
- // } failure:^(NSError *error) {}];
-
- SearchResultViewController *vc = [SearchResultViewController new];
- vc.txt = keyword;
- vc.hidesBottomBarWhenPushed = true;
- [self.navigationController pushViewController:vc animated:true];
- }
- -(void)playItem{
- ZFNormalViewController *vc = [[ZFNormalViewController alloc] init];
- vc.vid = self.vid;
- vc.hidesBottomBarWhenPushed = true;
- [self.navigationController pushViewController:vc animated:true];
- }
- #pragma mark -- collicationdelegate
- //返回分区个数
- -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
- return 1;
- }
- //返回每个分区的item个数
- -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- if(self.searchList.count>0){
- return 3+self.searchList.count;
- }else{
- return 2;
- }
- }
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- __weak typeof (self) weakSelf = self;
- if(self.searchList.count>0){
- if(indexPath.row == 0){
- SearchTitCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([SearchTitCell class]) forIndexPath:indexPath];
- cell.delBlock = ^{
- [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"mylocationhistory"];
- weakSelf.searchList = [NSMutableArray array];
- [weakSelf.collect reloadData];
- };
- return cell;
- }else if(indexPath.row<=self.searchList.count){
- SearchItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([SearchItemCell class]) forIndexPath:indexPath];
- cell.nameLab.text = self.searchList[indexPath.row - 1];
- return cell;
- }else if(indexPath.row == self.searchList.count+1){
- FoundCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FoundCell class]) forIndexPath:indexPath];
- cell.hotkeyDataArr = self.hotkeyDataArr;
- cell.tapBlock = ^(NSString * _Nonnull str) {
- [weakSelf search:str];
- };
- return cell;
- }else{
- HotSearchCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([HotSearchCell class]) forIndexPath:indexPath];
- cell.hotMoviesArr = self.hotMoviesArr;
- cell.tapBlock = ^(int vid) {
- weakSelf.vid = vid;
- [weakSelf playItem];
- };
- return cell;
- }
- }else{
- if(indexPath.row == 0){
- FoundCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FoundCell class]) forIndexPath:indexPath];
- cell.hotkeyDataArr = self.hotkeyDataArr;
- cell.tapBlock = ^(NSString * _Nonnull str) {
- [weakSelf search:str];
- };
- return cell;
- }else{
- HotSearchCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([HotSearchCell class]) forIndexPath:indexPath];
- cell.hotMoviesArr = self.hotMoviesArr;
- cell.tapBlock = ^(int vid) {
- weakSelf.vid = vid;
- [weakSelf playItem];
- };
- return cell;
- }
- }
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- if(self.searchList.count>0){
- if(indexPath.row == 0){
- //do nothing
- }else if(indexPath.row<=self.searchList.count){
- [self search:self.searchList[indexPath.row - 1]];
- }
- }
- }
- #pragma mark - UICollectionViewDelegateFlowLayout
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- if(self.searchList.count>0){
- if(indexPath.row == 0){
- return CGSizeMake(SCREEN_WIDTH-24, 37);
- }else if(indexPath.row<=self.searchList.count){
- NSString *str=self.searchList[indexPath.row-1];
- return CGSizeMake(str.length*12+25, 30);
- }else if(indexPath.row == self.searchList.count+1){
- return CGSizeMake(SCREEN_WIDTH-24, 160);
- }else{
- return CGSizeMake(SCREEN_WIDTH-24, 415+58*4);
- }
- }else{
- if(indexPath.row == 0){
- return CGSizeMake(SCREEN_WIDTH-24, 160);
- }else{
- return CGSizeMake(SCREEN_WIDTH-24, 415+58*4);
- }
- }
- }
- - (UICollectionView *)collect {
-
- if (!_collect) {
- UICollectionViewLeftAlignedLayout *layout = [[UICollectionViewLeftAlignedLayout alloc] init];
- layout.minimumLineSpacing = 8; //跟滚动方向相同的间距
- layout.minimumInteritemSpacing = 8; //跟滚动方向垂直的间距
- layout.scrollDirection = UICollectionViewScrollDirectionVertical;
- _collect = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH-60, 110) collectionViewLayout:layout];
- _collect.contentInset = UIEdgeInsetsMake(0, 12, 12, 12);
- //注册cell
- [_collect registerClass:[SearchTitCell class] forCellWithReuseIdentifier:@"SearchTitCell"];
- [_collect registerClass:[SearchItemCell class] forCellWithReuseIdentifier:@"SearchItemCell"];
- [_collect registerClass:[FoundCell class] forCellWithReuseIdentifier:@"FoundCell"];
- [_collect registerClass:[HotSearchCell class] forCellWithReuseIdentifier:@"HotSearchCell"];
- _collect.dataSource = self;
- _collect.delegate = self;
- _collect.backgroundColor = rgba(18, 23, 41, 1);
- }
- return _collect;
- }
- -(SearchCommonBarView *)barView{
- if(!_barView){
- CGFloat h=0;
- if(@available(iOS 13.0, *)){
- UIStatusBarManager *sc= [UIApplication sharedApplication].windows.firstObject.windowScene.statusBarManager;
- CGRect f=sc.statusBarFrame;
- h=f.size.height;
- }else{
- h=[UIApplication sharedApplication].statusBarFrame.size.height;
- }
- if(h>=40){
- h=30;
- }
- _barView =[[SearchCommonBarView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 72-20+h)];
- _barView.backgroundColor = rgba(18, 23, 41, 1);
- __weak typeof(self) weakSelf = self;
- _barView.searchAction = ^(NSString * _Nonnull tit) {
- [weakSelf search:tit];
- };
- }
- return _barView;
- }
- @end
- #pragma mark -- SearchTitCell
- @interface SearchTitCell()
- @end
- @implementation SearchTitCell
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self setUp];
- }
- return self;
- }
- -(void)delAction{
- if(self.delBlock){
- self.delBlock();
- }
- }
- - (void)setUp {
- self.backgroundColor = [UIColor clearColor];
- UILabel *nameLab = [UILabel new];
- nameLab.text = @"搜索记录";
- nameLab.font = [UIFont boldSystemFontOfSize:16];
- nameLab.textColor = [UIColor whiteColor];
- [self.contentView addSubview:nameLab];
- [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(0);
- make.bottom.equalTo(self.contentView).offset(-4);
- }];
-
- UIImageView *iv = [UIImageView new];
- iv.image = [UIImage imageNamed:@"Frame90"];
- iv.userInteractionEnabled = true;
- UITapGestureRecognizer *g=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(delAction)];
- [iv addGestureRecognizer:g];
- [self.contentView addSubview:iv];
- [iv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView).offset(0);
- make.centerY.equalTo(nameLab);
- }];
- }
- @end
- @implementation SearchItemCell
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self setUp];
- }
- return self;
- }
- - (void)setUp {
- self.backgroundColor = [UIColor clearColor];
- UIView *bgView =[UIView new];
- bgView.backgroundColor = rgba(52, 56, 68, 1);
- [self.contentView addSubview:bgView];
- [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.contentView);
- }];
-
- UILabel *nameLab = [UILabel new];
- self.nameLab = nameLab;
- nameLab.text = @"流浪地球";
- nameLab.font = [UIFont boldSystemFontOfSize:12];
- nameLab.textColor = rgba(255, 255, 255, 0.8);
- [bgView addSubview:nameLab];
- [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(bgView);
- }];
-
- bgView.layer.cornerRadius = 16;
- bgView.layer.masksToBounds = true;
- }
- @end
- @interface FoundCell()
- @property(nonatomic,strong)NSArray *nameArr;
- @property(nonatomic,strong)NSArray *arr;
- @end
- @implementation FoundCell
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self setUp];
- }
- return self;
- }
- -(void)setHotkeyDataArr:(NSArray *)hotkeyDataArr{
- if(![hotkeyDataArr isKindOfClass:[NSArray class]]){
- hotkeyDataArr = @[];
- }
- _hotkeyDataArr = hotkeyDataArr;
- NSMutableArray *arr = [NSMutableArray array];
- self.arr = arr;
- if(hotkeyDataArr.count){
- [arr addObjectsFromArray:hotkeyDataArr];
- }
- if(self.nameArr.count){
- [arr addObjectsFromArray:self.nameArr];
- }
- // if(hotkeyDataArr.count<8){
- // [arr addObjectsFromArray:hotkeyDataArr];
- // [arr addObjectsFromArray:self.nameArr];
- // self.nameArr = arr;
- // }else{
- // self.nameArr = hotkeyDataArr;
- // [arr addObjectsFromArray:hotkeyDataArr];
- // }
- for(int i = 0;i<8;i++){
- UILabel *item = [self.contentView viewWithTag:100+i];
- BOOL shouldHide = i>=arr.count;
- item.hidden = shouldHide;
- if(shouldHide){
- item.attributedText = nil;
- item.text = @"";
- continue;
- }
- if(i<3){
- NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d",i+1] attributes:@{NSForegroundColorAttributeName:rgba(255, 212, 0, 1),
- NSFontAttributeName:[UIFont boldSystemFontOfSize:14]}];
- NSString *str=[NSString stringWithFormat:@" %@",arr[i]];
- NSMutableAttributedString *attrString2 = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],
- NSFontAttributeName:[UIFont boldSystemFontOfSize:14]}];
- [attrString1 appendAttributedString:attrString2];
- item.attributedText = attrString1;
- }else{
- item.text =[NSString stringWithFormat:@"%d %@",i+1,arr[i]];
- }
- }
- }
- -(void)searchAct:(UITapGestureRecognizer *)g{
- NSInteger x = g.view.tag - 100;
- if(x<0 || x>=self.arr.count){
- return;
- }
- NSString *str = self.arr[x];
- if(self.tapBlock){
- self.tapBlock(str);
- }
- }
- - (void)setUp {
- self.backgroundColor = [UIColor clearColor];
-
- UILabel *nameLab = [UILabel new];
- nameLab.text = @"搜索发现";
- nameLab.font = [UIFont boldSystemFontOfSize:16];
- nameLab.textColor = rgba(255, 212, 0, 1);
- [self.contentView addSubview:nameLab];
- [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(0);
- make.top.equalTo(self.contentView).offset(16);
- }];
- self.nameArr = @[@"检查风云",@"宇宙探索编辑部",@"昆仑神宫",@"不止不休",@"幕后玩家",@"我的女友们",@"普罗米修斯",@"古董局中局"];
- for(int i=0;i<8;i++){
- UILabel *item = [UILabel new];
- item.tag = 100+i;
- UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(searchAct:)];
- item.userInteractionEnabled = true;
- [item addGestureRecognizer:g];
- if(i<3){
- NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d",i+1] attributes:@{NSForegroundColorAttributeName:rgba(255, 212, 0, 1),
- NSFontAttributeName:[UIFont boldSystemFontOfSize:14]}];
- NSMutableAttributedString *attrString2 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",self.nameArr[i]] attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],
- NSFontAttributeName:[UIFont systemFontOfSize:14]}];
- [attrString1 appendAttributedString:attrString2];
- item.attributedText = attrString1;
- }else{
- item.font = [UIFont boldSystemFontOfSize:14];
- item.textColor = [UIColor whiteColor];
- item.text =[NSString stringWithFormat:@"%d %@",i+1,self.nameArr[i]];
- }
- [self.contentView addSubview:item];
- [item mas_makeConstraints:^(MASConstraintMaker *make) {
- if(i<4){
- make.left.equalTo(self.contentView).offset(1);
- }else{
- make.left.equalTo(self.contentView).offset(180-12);
- }
- make.top.equalTo(nameLab.mas_bottom).offset(12+30*(i%4));
- }];
- }
- }
- @end
- @implementation HotSearchCell
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self setUp];
- }
- return self;
- }
- -(void)tapAct:(UITapGestureRecognizer *)g{
- NSInteger x = g.view.tag - 200;
- if(self.hotMoviesArr.count>x){
- int vid = [self.hotMoviesArr[x][@"vid"] intValue];
- if(self.tapBlock){
- self.tapBlock(vid);
- }
- }
- }
- -(void)setHotMoviesArr:(NSArray *)hotMoviesArr{
- if(![hotMoviesArr isKindOfClass:[NSArray class]]){
- hotMoviesArr = @[];
- }
- _hotMoviesArr = hotMoviesArr;
- UIView *container = [self.contentView viewWithTag:100];
- for(int i=0;i<10;i++){
- UIView *iv = [container viewWithTag:200+i];
- BOOL shouldHide = i >= hotMoviesArr.count;
- iv.hidden = shouldHide;
- if(shouldHide){
- continue;
- }
- UIImageView *icon = [iv viewWithTag:300];
- [icon sd_setImageWithURL:[NSURL URLWithString:hotMoviesArr[i][@"vertical_cover_url"]]];
-
- UILabel *lab1 = [iv viewWithTag:301];
- if(i<3){
- NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d",i+1] attributes:@{NSForegroundColorAttributeName:rgba(255, 61, 0, 1),
- NSFontAttributeName:[UIFont boldSystemFontOfSize:14]}];
- NSString *str = [NSString stringWithFormat:@" %@",hotMoviesArr[i][@"ch_name"]];
- NSMutableAttributedString *attrString2 = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],
- NSFontAttributeName:[UIFont systemFontOfSize:14]}];
- [attrString1 appendAttributedString:attrString2];
- lab1.attributedText = attrString1;
- }else{
- lab1.text =[NSString stringWithFormat:@"%d %@",i+1,hotMoviesArr[i][@"ch_name"]];
- }
-
- UILabel *lab2 = [iv viewWithTag:302];
- // lab2.text = @"2023 / 9.6分 / 剧情 / 美国 / 沈腾";
- NSDate* date = [NSDate dateWithTimeIntervalSince1970:[hotMoviesArr[i][@"screen_time"] doubleValue]];
- NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
- [formatter setDateFormat:@"yyyy"];
- NSString* dateString = [formatter stringFromDate:date];
- NSString *c = [NSString stringWithFormat:@"%@ / %.1f ",dateString,[hotMoviesArr[i][@"score"] floatValue]];
- NSArray *class_list = hotMoviesArr[i][@"class_list"];
- if(![class_list isKindOfClass:[NSArray class]]){
- class_list = @[];
- }
- for(int j=0;j<class_list.count;j++){
- c = [NSString stringWithFormat:@"%@/ %@ ",c,class_list[j][@"classname"]];
- }
- c = [NSString stringWithFormat:@"%@ / %@",c,hotMoviesArr[i][@"country"]];
- lab2.text = c;
- }
- }
- - (void)setUp {
- self.backgroundColor = [UIColor clearColor];
-
- UIView *bg = [UIView new];
- bg.backgroundColor = rgba(52, 56, 68, 1);
- bg.tag = 100;
- [self.contentView addSubview:bg];
- [bg mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView).offset(16);
- make.left.equalTo(self.contentView).offset(0);
- make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-24, 400+58*4));
- }];
-
- UILabel *tit = [UILabel new];
- NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:@"热搜" attributes:@{NSForegroundColorAttributeName:rgba(255, 61, 0, 1),
- NSFontAttributeName:[UIFont boldSystemFontOfSize:16]}];
- NSMutableAttributedString *attrString2 = [[NSMutableAttributedString alloc] initWithString:@"Hot" attributes:@{NSForegroundColorAttributeName:rgba(255, 212, 0, 1),
- NSFontAttributeName:[UIFont boldSystemFontOfSize:12]}];
- [attrString1 appendAttributedString:attrString2];
- tit.attributedText = attrString1;
- [bg addSubview:tit];
- [tit mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(bg).offset(16);
- make.left.equalTo(bg).offset(12);
- }];
-
-
- for(int i=0;i<10;i++){
- UIView *iv = [UIView new];
- // iv.backgroundColor = [UIColor grayColor];
- iv.tag = 200+i;
- UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAct:)];
- [iv addGestureRecognizer:g];
- [bg addSubview:iv];
- [iv mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(tit.mas_bottom).offset(12+58*i);
- make.left.right.equalTo(bg);
- make.height.mas_equalTo(@46);
- }];
-
- UIImageView *icon = [UIImageView new];
- icon.image = [UIImage imageNamed:@""];
- // icon.backgroundColor = [UIColor redColor];
- icon.tag = 300;
- [iv addSubview:icon];
- [icon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(iv);
- make.left.equalTo(iv).offset(12);
- make.size.mas_equalTo(CGSizeMake(35, 46));
- }];
-
- UILabel *lab1 = [UILabel new];
- lab1.tag = 301;
- if(i<3){
- NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d",i+1] attributes:@{NSForegroundColorAttributeName:rgba(255, 61, 0, 1),
- NSFontAttributeName:[UIFont boldSystemFontOfSize:14]}];
- NSMutableAttributedString *attrString2 = [[NSMutableAttributedString alloc] initWithString:@" 检查风云" attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],
- NSFontAttributeName:[UIFont systemFontOfSize:14]}];
- [attrString1 appendAttributedString:attrString2];
- lab1.attributedText = attrString1;
- }else{
- lab1.font = [UIFont systemFontOfSize:14];
- lab1.textColor = [UIColor whiteColor];
- lab1.text =[NSString stringWithFormat:@"%d %@",i+1,@" 检查风云"];
- }
-
- [iv addSubview:lab1];
- [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(icon.mas_right).offset(9);
- make.top.equalTo(icon).offset(3);
- }];
-
- UILabel *lab2 = [UILabel new];
- lab2.tag = 302;
- lab2.text = @"2023 / 9.6分 / 剧情 / 美国 / 沈腾";
- lab2.textColor = rgba(255, 255, 255, 0.4);
- lab2.font=[UIFont systemFontOfSize:12];
- [iv addSubview:lab2];
- [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(lab1);
- make.top.equalTo(lab1.mas_bottom).offset(6);
- }];
-
- icon.layer.cornerRadius = 6;
- icon.layer.masksToBounds = true;
- }
-
- bg.layer.cornerRadius = 12;
- bg.layer.masksToBounds = true;
- }
- @end
|