123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- //
- // FKRecommendlimitBuyCell.m
- // FirstLink
- //
- // Created by jack on 15/11/30.
- // Copyright © 2015年 FirstLink. All rights reserved.
- //
- #import "FKRecoLimitBuyCell.h"
- @interface FKLimitBuySingleCell ()
- @end
- @implementation FKLimitBuySingleCell
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- [self addAllSubviews];
- }
- return self;
- }
- - (void)addAllSubviews {
- [self.contentView addSubview:self.imageView];
- [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView);
- make.centerX.equalTo(self.contentView);
- make.left.equalTo(self.contentView).offset(6);
- make.right.equalTo(self.contentView).offset(-6);
- make.height.equalTo(self.imageView.mas_width);
- }];
-
- [self.imageView addSubview:self.statusImageView];
- [self.statusImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self.imageView);
- }];
-
- [self.contentView addSubview:self.priceLabel];
- [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.imageView.mas_bottom).offset(4);
- make.left.right.equalTo(self.contentView);
- }];
-
- [self.contentView addSubview:self.buyButton];
- [self.buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.priceLabel.mas_bottom).offset(8);
- make.centerX.equalTo(self.contentView);
- make.height.mas_equalTo(18);
- make.width.mas_equalTo(65);
- }];
- }
- #pragma mark - property
- - (UIImageView *)imageView {
- if (!_imageView) {
- _imageView = [[UIImageView alloc]init];
- _imageView.userInteractionEnabled = YES;
- _imageView.contentMode = UIViewContentModeScaleAspectFit;
- }
- return _imageView;
- }
- - (UIImageView *)statusImageView {
- if (!_statusImageView) {
- _statusImageView = [[UIImageView alloc] init];
- _statusImageView.image = [UIImage imageNamed:@"SoldOutIcon"];
- _statusImageView.hidden = YES;
- }
- return _statusImageView;
- }
- - (UILabel *)priceLabel {
- if (!_priceLabel) {
- _priceLabel = [[UILabel alloc]init];
- _priceLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _priceLabel;
- }
- - (UIButton *)buyButton {
- if (!_buyButton) {
- _buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _buyButton.userInteractionEnabled = NO;
- _buyButton.layer.cornerRadius = 9;
- _buyButton.layer.borderWidth = 1.0/[UIScreen mainScreen].scale;
- _buyButton.layer.borderColor = UIColorFromRGB(0xff6362).CGColor;
- [_buyButton setTitle:@"立即抢购" forState:UIControlStateNormal];
- [_buyButton setTitleColor:UIColorFromRGB(0xff624a) forState:UIControlStateNormal];
- [_buyButton.titleLabel setFont:[UIFont systemFontOfSize:11]];
- }
- return _buyButton;
- }
- @end
- #import "FKRecommendViewModel.h"
- @interface FKRecoLimitBuyCell ()
- <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>
- @property (nonatomic, strong) UICollectionView *collectionView;
- @property (nonatomic, weak ) FKRecAreaItem *dataSource;
- @end
- static const NSInteger LIMITELEMENTCOUNT = 3;
- @implementation FKRecoLimitBuyCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
- self.selectionStyle = UITableViewCellSelectionStyleNone;
-
- [self addAllSubviews];
- }
- return self;
- }
- - (void)fk_configWithViewModel:(FKRecommendViewModel *)viewModel indexPath:(NSIndexPath *)indexPath {
- if ([viewModel isKindOfClass:[FKRecommendViewModel class]]) {
- self.dataSource = viewModel.limitBuyArea;
- [self.collectionView reloadData];
- }
- }
- #pragma mark - UICollectionViewDataSource
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.dataSource.dataArray.count;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- return CGSizeMake([FKRecoLimitBuyCell width:self.dataSource.dataArray.count], [FKRecoLimitBuyCell height:self.dataSource.dataArray.count]);
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- FKLimitBuySingleCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FKLimitBuySingleCell class])
- forIndexPath:indexPath];
- if (indexPath.row < self.dataSource.dataArray.count) {
- FKLimitBuyItem *item = self.dataSource.dataArray[indexPath.row];
-
- [cell.imageView setImageWithURL:item.photoURL cdnWidth:[FKRecoLimitBuyCell width:self.dataSource.dataArray.count]];
- cell.statusImageView.hidden = [item.salable isEqualToString:@"1"];
-
- NSString *price = item.price ? [NSString stringWithFormat:@"¥%@ ", [FLStringHelper convertFenToYuan:item.price]] : nil;
- NSString *originalPrice = item.originalPrice ? [NSString stringWithFormat:@"¥%@", [FLStringHelper convertFenToYuan:item.originalPrice]] : nil;
-
- NSAttributedString *attributeString = [FLStringHelper attStringWithText:price
- color:UIColorFromRGB(0x333333)
- font:[UIFont boldSystemFontOfSize:12]
- subText:originalPrice
- subColor:UIColorFromRGB(0x999999)
- subFont:[UIFont systemFontOfSize:9]];
- if (attributeString) {
- cell.priceLabel.attributedText = attributeString;
- }
- }
- return cell;
- }
- - (IBAction)clickLargeImageViewGesture:(UIGestureRecognizer *)gesture {
- if (self.delegate && [self.delegate respondsToSelector:@selector(recommendClickCell:atIndexPath:offset:)]) {
- [self.delegate recommendClickCell:self atIndexPath:self.indexPath offset:gesture.view.tag];
- }
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- if (self.delegate && [self.delegate respondsToSelector:@selector(recommendClickCell:atIndexPath:offset:)]) {
- [self.delegate recommendClickCell:self atIndexPath:self.indexPath offset:indexPath.row];
- }
- }
- #pragma mark - Action
- - (IBAction)clickViewGesture:(UIGestureRecognizer *)gesture {
- if (self.delegate && [self.delegate respondsToSelector:@selector(recommendClickCell:atIndexPath:offset:)]) {
- [self.delegate recommendClickCell:self atIndexPath:self.indexPath offset:gesture.view.tag];
- }
- }
- #pragma mark - Layout
- - (void)addAllSubviews {
- [self.contentView addSubview:self.collectionView];
- [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.contentView);
- }];
- }
- + (CGFloat)width:(CGFloat)itemCount {
- CGFloat count = 3.5;
- if (IS_IPHONE_4 || IS_IPHONE_5) {
- count = 2.7;
- }
-
- if (itemCount <= LIMITELEMENTCOUNT) {
- count = LIMITELEMENTCOUNT;
- }
- return (int)(UISCREENWIDTH/count);
- }
- + (CGFloat)height:(CGFloat)itemCount {
- CGFloat width = [FKRecoLimitBuyCell width:itemCount];
- CGFloat height = (width - 6 - 6);
- return (height + 58);
- }
- #pragma mark - Property
- - (UICollectionView *)collectionView {
- if (!_collectionView) {
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.headerReferenceSize = CGSizeZero;
- layout.footerReferenceSize = CGSizeZero;
- layout.minimumInteritemSpacing = 0;
- layout.minimumLineSpacing = 0;
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
-
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- _collectionView.dataSource = self;
- _collectionView.delegate = self;
- _collectionView.backgroundColor = [UIColor whiteColor];
- _collectionView.alwaysBounceVertical = NO;
- _collectionView.showsHorizontalScrollIndicator = NO;
- _collectionView.scrollsToTop = NO;
-
- [_collectionView registerClass:[FKLimitBuySingleCell class] forCellWithReuseIdentifier:NSStringFromClass([FKLimitBuySingleCell class])];
- }
- return _collectionView;
- }
- @end
|