No Description

FKVipFeatureCell.m 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // FKVipFeatureCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/9/11.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "FKVipFeatureCell.h"
  9. #import "FKVipPrivilegeCollectionCell.h"
  10. #import "FUKit.h"
  11. #import "FLControllerHelper.h"
  12. #import "WebViewController.h"
  13. @interface FKVipFeatureCell ()
  14. <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, FKCardSegmentViewDelegate>
  15. @property (nonatomic, strong) FKCardSegmentView *cardSegmentView;
  16. @property (nonatomic, strong) UICollectionView *collectionView;
  17. @end
  18. @implementation FKVipFeatureCell
  19. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  20. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  21. if (self) {
  22. [self addAllSubviews];
  23. self.selectionStyle = UITableViewCellSelectionStyleNone;
  24. }
  25. return self;
  26. }
  27. - (void)addAllSubviews {
  28. [self.contentView addSubview:self.cardSegmentView];
  29. [self.cardSegmentView mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.left.top.right.equalTo(self.contentView);
  31. make.height.mas_equalTo(48);
  32. }];
  33. [self.contentView addSubview:self.collectionView];
  34. [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.right.equalTo(self.contentView);
  36. make.top.equalTo(self.cardSegmentView.mas_bottom).offset(22);
  37. make.height.mas_equalTo(200);
  38. }];
  39. [self.contentView addSubview:self.buyButton];
  40. [self.buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.equalTo(self.contentView).offset(14);
  42. make.right.equalTo(self.contentView).offset(-14);
  43. make.top.equalTo(self.collectionView.mas_bottom).offset(20);
  44. make.height.mas_equalTo(40);
  45. }];
  46. }
  47. #pragma mark - UICollectionViewDataSource, UICollectionViewDelegate
  48. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  49. return 6;
  50. }
  51. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  52. if (indexPath.row == 1 || indexPath.row == 4) {
  53. return CGSizeMake(136, 90);
  54. }
  55. return CGSizeMake((UISCREENWIDTH - 2*12 - 136) / 2, 90);
  56. }
  57. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  58. FKVipPrivilegeCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FKVipPrivilegeCollectionCell class])
  59. forIndexPath:indexPath];
  60. cell.imgView.image = [self.viewModel imageAtIndex:indexPath.row];
  61. cell.titleLabel.attributedText = [self.viewModel attributedTitleAtIndex:indexPath.row];
  62. if (indexPath.row == 1) {
  63. cell.lockImgView.hidden = NO;
  64. cell.futureImgView.hidden = NO;
  65. } else {
  66. cell.lockImgView.hidden = YES;
  67. cell.futureImgView.hidden = YES;
  68. }
  69. return cell;
  70. }
  71. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  72. if (indexPath.row == 1) {
  73. return;
  74. }
  75. NSString *index = @[@"1", @"2", @"3", @"4", @"5", @"6"][indexPath.row];
  76. NSString *urlString = nil;
  77. if ((self.viewModel.segmentType == kCardSegmentTypeVip)) {
  78. urlString = [NSString stringWithFormat:@"%@/vip-guide/member.html?isCommon=true&iconIndex=%@", [[FKServerUtil sharedInstance] webServer], index];
  79. } else {
  80. urlString = [NSString stringWithFormat:@"%@/vip-guide/member.html?isCommon=false&iconIndex=%@", [[FKServerUtil sharedInstance] webServer], index];
  81. }
  82. WebViewController *newViewController = [[WebViewController alloc] init];
  83. newViewController.url = urlString;
  84. newViewController.hidesBottomBarWhenPushed = YES;
  85. [[FLControllerHelper currentController].navigationController pushViewController:newViewController animated:YES];
  86. }
  87. #pragma mark - FKCardSegmentViewDelegate
  88. - (void)cardSegmentView:(FKCardSegmentView *)view didSelectWithVipIndex:(kCardSegmentIndex)vip {
  89. if (kCardSegmentIndexLeft == vip) {
  90. self.viewModel.segmentType = kCardSegmentTypeVip;
  91. self.buyButton.tag = 0;
  92. } else if (kCardSegmentIndexRight == vip) {
  93. self.viewModel.segmentType = kCardSegmentTypeSuperVip;
  94. self.buyButton.tag = 1;
  95. }
  96. [self.collectionView reloadData];
  97. }
  98. #pragma mark - Property
  99. - (FKCardSegmentView *)cardSegmentView {
  100. if (!_cardSegmentView) {
  101. _cardSegmentView = [FKCardSegmentView new];
  102. _cardSegmentView.delegate = self;
  103. }
  104. return _cardSegmentView;
  105. }
  106. - (UICollectionView *)collectionView {
  107. if (!_collectionView) {
  108. UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
  109. layout.minimumLineSpacing = CGFLOAT_MIN;
  110. layout.minimumInteritemSpacing = CGFLOAT_MIN;
  111. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  112. _collectionView.showsVerticalScrollIndicator = NO;
  113. _collectionView.alwaysBounceVertical = YES;
  114. _collectionView.dataSource = self;
  115. _collectionView.delegate = self;
  116. _collectionView.backgroundColor = UIColorFromRGB(0xffffff);
  117. _collectionView.contentInset = UIEdgeInsetsMake(0, 12, 0, 12);
  118. _collectionView.scrollEnabled = NO;
  119. [_collectionView registerClass:[FKVipPrivilegeCollectionCell class] forCellWithReuseIdentifier:NSStringFromClass([FKVipPrivilegeCollectionCell class])];
  120. }
  121. return _collectionView;
  122. }
  123. - (UIButton *)buyButton {
  124. if (!_buyButton) {
  125. _buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
  126. _buyButton.layer.cornerRadius = 4.0;
  127. _buyButton.backgroundColor = UIColorFromRGB(0xff5656);
  128. [_buyButton setTitle:@"立即购买" forState:UIControlStateNormal];
  129. [_buyButton.titleLabel setFont:[UIFont systemFontOfSize:18]];
  130. [_buyButton setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
  131. _buyButton.tag = 0;
  132. }
  133. return _buyButton;
  134. }
  135. @end