123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- //
- // FKVipPrivilegeDetailCell.m
- // FirstLink
- //
- // Created by ascii on 2017/5/18.
- // Copyright © 2017年 FirstLink. All rights reserved.
- //
- #import "FKVipPrivilegeDetailCell.h"
- #import "FKVipPrivilegeDetailCollectionCell.h"
- #import "FKVipBuyRuleItem.h"
- static NSString * const kLeftFixSpaceString = @" ";
- static NSString * const kRightFixSpaceString = @" ";
- @interface FKVipPrivilegeDetailCell ()
- <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UICollectionView *collectionView;
- @property (nonatomic, strong) NSArray<FKVipBuyRuleItem *> *buyRuleArray;
- @property (nonatomic, strong) NSArray *titleArray;
- @end
- @implementation FKVipPrivilegeDetailCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- self.selectionStyle = UITableViewCellSelectionStyleNone;
-
- [self setupViews];
- }
- return self;
- }
- #pragma mark - UICollectionViewDataSource, UICollectionViewDelegate
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return 4 + 4*self.buyRuleArray.count;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- return CGSizeMake([FKVipPrivilegeDetailCell widthForCellAtIndex:indexPath.row], [FKVipPrivilegeDetailCell heightForCellAtIndex:indexPath.row]);
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- FKVipPrivilegeDetailCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FKVipPrivilegeDetailCollectionCell class])
- forIndexPath:indexPath];
-
- if (indexPath.row < 4) {
- NSString *title = self.titleArray[indexPath.row];
- if (indexPath.row < 2) {
- cell.titleLabel.text = [NSString stringWithFormat:@"%@%@", kLeftFixSpaceString, title];
- } else {
- cell.titleLabel.text = [NSString stringWithFormat:@"%@%@", kRightFixSpaceString, title];
- }
- } else {
- NSInteger index = indexPath.row/4 - 1;
- if (index >= 0 && index < self.buyRuleArray.count) {
- FKVipBuyRuleItem *item = self.buyRuleArray[index];
- switch (indexPath.row%4) {
- case 0: {
- cell.titleLabel.text = [NSString stringWithFormat:@"%@%@", kLeftFixSpaceString, [item couponString]];
- break;
- }
- case 1: {
- cell.titleLabel.text = [NSString stringWithFormat:@"%@%@", kLeftFixSpaceString, [item discountString]];
- break;
- }
- case 2: {
- cell.titleLabel.text = [NSString stringWithFormat:@"%@%@", kRightFixSpaceString, [item validTimeString]];
- break;
- }
- case 3: {
- cell.titleLabel.text = [NSString stringWithFormat:@"%@%@", kRightFixSpaceString, item.realPrice];
- break;
- }
- default:
- break;
- }
- }
- }
-
- return cell;
- }
- #pragma mark - Action
- - (void)reloadData:(NSArray<FKVipBuyRuleItem *> *)buyRuleArray {
- self.buyRuleArray = buyRuleArray;
- [self.collectionView reloadData];
- }
- #pragma mark - Method
- + (CGFloat)widthForCellAtIndex:(NSInteger)index {
- if (index%4 >= 2) {
- return 60;
- }
- return (int)((UISCREENWIDTH - 2*18 - 2*60)/2);
- }
- + (CGFloat)heightForCellAtIndex:(NSInteger)index {
- if (index < 4) {
- return 37;
- }
- return 36;
- }
- - (CGFloat)margin {
- return (float)(UISCREENWIDTH - 2*[FKVipPrivilegeDetailCell widthForCellAtIndex:0] - 2*[FKVipPrivilegeDetailCell widthForCellAtIndex:3])/2.0;
- }
- - (void)setupViews {
- [self.contentView addSubview:self.titleLabel];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(18);
- make.top.equalTo(self.contentView).offset(24);
- }];
-
- [self.contentView addSubview:self.collectionView];
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset([self margin]);
- make.right.equalTo(self.contentView).offset(-[self margin]);
- make.top.equalTo(self.titleLabel.mas_bottom).offset(20);
- make.height.mas_equalTo(37+36*3);
- }];
- }
- #pragma mark - Property
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [UILabel new];
- _titleLabel.font = [UIFont systemFontOfSize:14];
- _titleLabel.textColor = UIColorFromRGB(0x333333);
- _titleLabel.text = @"会员使用说明:";
- }
- return _titleLabel;
- }
- - (UICollectionView *)collectionView {
- if (!_collectionView) {
- UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
- layout.minimumLineSpacing = CGFLOAT_MIN;
- layout.minimumInteritemSpacing = CGFLOAT_MIN;
-
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _collectionView.showsVerticalScrollIndicator = NO;
- _collectionView.alwaysBounceVertical = YES;
-
- _collectionView.dataSource = self;
- _collectionView.delegate = self;
-
- _collectionView.backgroundColor = UIColorFromRGB(0xffffff);
- _collectionView.contentInset = UIEdgeInsetsZero;
- _collectionView.scrollEnabled = NO;
-
- [_collectionView registerClass:[FKVipPrivilegeDetailCollectionCell class]
- forCellWithReuseIdentifier:NSStringFromClass([FKVipPrivilegeDetailCollectionCell class])];
-
- _collectionView.layer.borderColor = UIColorFromRGB(0xe5e5e5).CGColor;
- _collectionView.layer.borderWidth = 1.0/[UIScreen mainScreen].scale;
- }
- return _collectionView;
- }
- - (NSArray *)titleArray {
- if (!_titleArray) {
- _titleArray = @[@"包邮券", @"会员价", @"有效期", @"价格"];
- }
- return _titleArray;
- }
- @end
|