1
This commit is contained in:
82
keyBoard/Class/Pay/V/KBVipReviewListCell.m
Normal file
82
keyBoard/Class/Pay/V/KBVipReviewListCell.m
Normal 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
|
||||
|
||||
Reference in New Issue
Block a user