This commit is contained in:
2025-11-14 19:48:15 +08:00
parent 4f2e80e482
commit dace0a9309
21 changed files with 792 additions and 19 deletions

View File

@@ -0,0 +1,82 @@
//
// KBVipReviewListCell.m
// keyBoard
//
// Cell UICollectionView
//
#import "KBVipReviewListCell.h"
#import "KBVipReviewItemCell.h"
static NSString * const kKBVipReviewItemCellId = @"kKBVipReviewItemCellId";
@interface KBVipReviewListCell () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collectionView; //
@property (nonatomic, strong) NSArray<NSDictionary *> *data; //
@end
@implementation KBVipReviewListCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.contentView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(0, 0, 0, 0));
}];
//
_data = @[
@{@"name":@"Sdsd666", @"text":@"I Highly Recommend This App. It Taught Me How To Chat"},
@{@"name":@"Joyce", @"text":@"Great keyboard and AI features!"},
@{@"name":@"Luna", @"text":@"Amazing app, love it."},
@{@"name":@"Mark", @"text":@"Helps with chat and emotion."},
@{@"name":@"Alan", @"text":@"Useful personalized keyboard."},
@{@"name":@"Coco", @"text":@"Recommend to friends."},
];
}
return self;
}
#pragma mark - DataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.data.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
KBVipReviewItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kKBVipReviewItemCellId forIndexPath:indexPath];
NSDictionary *d = self.data[indexPath.item];
[cell configWithName:d[@"name"] text:d[@"text"]];
return cell;
}
#pragma mark - FlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGFloat w = floor((KB_SCREEN_WIDTH - 16 - 16 - 10) / 2.0); //
return CGSizeMake(MAX(120, w), 120);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return 10; }
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return 10; }
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(0, 16, 0, 16);
}
#pragma mark - Lazy
- (UICollectionView *)collectionView {
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.backgroundColor = UIColor.clearColor;
_collectionView.showsHorizontalScrollIndicator = NO;
_collectionView.dataSource = self;
_collectionView.delegate = self;
[_collectionView registerClass:KBVipReviewItemCell.class forCellWithReuseIdentifier:kKBVipReviewItemCellId];
if (@available(iOS 11.0, *)) {
_collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
}
return _collectionView;
}
@end