123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- //
- // ASHomeTipCell.m
- // Asteria
- //
- // Created by iOS on 2023/6/6.
- //
- #import "ASHomeTipCell.h"
- #import "ASHomeTipCollectCell.h"
- @interface ASHomeTipCell () <UICollectionViewDelegate,UICollectionViewDataSource>
- @property (nonatomic, strong) UICollectionView *collV;
- @property (nonatomic, strong) NSArray <NSString *>*titleArr;
- @property (nonatomic, strong) NSArray <NSString *>*imgArr;
- @end
- @implementation ASHomeTipCell
- - (void)setData {
- self.titleArr = [NSArray arrayWithObjects:@"USA UK CAN\nFREE SHIPPING",@"INTERNATIONAL\nEXPRESS SHIPPING",@"SECURE PAYMENTS\nCREDIT PAY IN 4",@"30 DAYS FREE\nRETURN/EXCHANGE", nil];
- self.imgArr = @[@"trade_tip",@"air_tip",@"pay_tip",@"box_tip"];
- [self.collV reloadData];
- }
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- self.contentView.backgroundColor = Col_FFF;
- self.backgroundColor = Col_FFF;
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- [self.contentView addSubview:self.collV];
- CGFloat margin = 10;
- CGFloat w = (KScreenWidth- 3*margin-1)/2;
- CGFloat h = w/172*55;
- CGFloat colH = h*2 + margin+2;
- [self.collV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView).offset(25);
- make.leading.trailing.equalTo(self.contentView);
- make.height.equalTo(@(colH));
- make.bottom.equalTo(self.contentView).offset(-25);
- }];
- [self setData];
- }
- return self;
- }
- - (UICollectionView *)collV {
- if (!_collV) {
- UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
- CGFloat margin = 10;
- CGFloat w = (KScreenWidth- 3*margin-1)/2;
- CGFloat h = w/172*55;
- CGFloat colH = h*2 + margin+2;
- layout.itemSize = CGSizeMake(w, h) ;
- layout.sectionInset = UIEdgeInsetsMake(0, margin, 0, margin);
- layout.minimumLineSpacing = margin;
- layout.minimumInteritemSpacing = margin;
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- UICollectionView *col = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, colH) collectionViewLayout:layout];
- [col registerClass:[ASHomeTipCollectCell class] forCellWithReuseIdentifier:@"ASHomeTipCollectCell"];
- col.backgroundColor = UIColor.whiteColor;
- col.showsHorizontalScrollIndicator = false;
- col.delegate = self;
- col.dataSource = self;
- _collV = col;
- }
- return _collV;
- }
- // MARK: - coll delegate datasource
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.titleArr.count;
- }
- - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- ASHomeTipCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ASHomeTipCollectCell" forIndexPath:indexPath];
- if (self.titleArr.count <= indexPath.row) {
- return cell;
- }
- NSString *titleStr = self.titleArr[indexPath.row];
- NSString *imgName = self.imgArr[indexPath.row];
- cell.imgV.image = [UIImage imageNamed:imgName];
- cell.titleLb.text = titleStr;
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
-
- }
- @end
|