123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- //
- // FKProAmazonScoreCell.m
- // FirstLink
- //
- // Created by ascii on 2017/1/16.
- // Copyright © 2017年 FirstLink. All rights reserved.
- //
- #import "FKProAmazonScoreCell.h"
- #import "FKProDetailViewModel.h"
- @interface FKProAmazonScoreCell ()
- @property (nonatomic, strong) UIImageView *bestSellerView;
- @property (nonatomic, strong) UILabel *rankLabel;
- @property (nonatomic, strong) UILabel *reviewCountLabel;
- @property (nonatomic, strong) UILabel *amazonTitleLabel;
- @property (nonatomic, strong) NSMutableArray *amazonStarArray;
- @end
- static NSInteger const AMAZON_STAR_COUNT = 5;
- @implementation FKProAmazonScoreCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
- [self addAllSubviews];
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.contentView.backgroundColor = [UIColor whiteColor];
- }
- return self;
- }
- - (void)fk_configWithViewModel:(FKProDetailViewModel *)viewModel indexPath:(NSIndexPath *)indexPath {
- if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) {
- FKProductInfoItem *item = viewModel.dataItem.productInfo;
-
- if (item.officialReviewCount.length > 0) {
- self.reviewCountLabel.text = [NSString stringWithFormat:@"%@人评", item.officialReviewCount];
- }
-
- NSInteger score = [item.officialScore integerValue];
- UIImageView *imageView = nil;
- for (NSInteger idx = 0; idx < AMAZON_STAR_COUNT; idx++) {
- imageView = self.amazonStarArray[idx];
-
- NSInteger tempIdx = (idx+1)*10;
- if (tempIdx <= score) {
- imageView.image = [UIImage imageNamed:@"amazonFullStar"];
- } else if (tempIdx > score && idx*10 < score) {
- imageView.image = [UIImage imageNamed:@"amazonHalfStar"];
- } else {
- imageView.image = [UIImage imageNamed:@"amazonEmptyStar"];
- }
- }
-
- if (item.officialRank) {
- self.bestSellerView.hidden = NO;
- self.rankLabel.text = [NSString stringWithFormat:@" #%@ Best Seller ", item.officialRank];
- [self.amazonTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.bestSellerView.mas_right).offset(8);
- make.centerY.equalTo(self.contentView);
- }];
- } else {
- self.bestSellerView.hidden = YES;
- [self.amazonTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(15);
- make.centerY.equalTo(self.contentView);
- }];
- }
- }
- }
- #pragma mark - Method
- + (CGFloat)height {
- return 30;
- }
- #pragma mark - Layout
- - (void)addAllSubviews {
- [self.contentView addSubview:self.bestSellerView];
- [self.bestSellerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(16);
- make.centerY.equalTo(self.contentView);
- }];
-
- [self.bestSellerView addSubview:self.rankLabel];
- [self.rankLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.bottom.equalTo(self.bestSellerView);
- make.right.equalTo(self.bestSellerView).offset(-8);
- }];
-
- [self.contentView addSubview:self.amazonTitleLabel];
- [self.amazonTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.bestSellerView.mas_right).offset(8);
- make.centerY.equalTo(self.contentView);
- }];
-
-
- self.amazonStarArray = [NSMutableArray array];
- for (NSInteger index = 0; index < AMAZON_STAR_COUNT; index++) {
- [self.amazonStarArray addObject:[UIImageView new]];
- }
-
- UIView *preView = self.amazonTitleLabel;
- for (UIView *view in self.amazonStarArray) {
- [self.contentView addSubview:view];
- CGFloat offset = (preView == self.amazonTitleLabel ? 8 : 4);
- [view mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(preView.mas_right).offset(offset);
- make.centerY.equalTo(preView);
- make.size.mas_equalTo(CGSizeMake(12, 11));
- }];
-
- preView = view;
- }
-
-
- UIView *lastStarView = self.amazonStarArray.lastObject;
- [self.contentView addSubview:self.reviewCountLabel];
- [self.reviewCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(lastStarView.mas_right).offset(12);
- make.centerY.equalTo(self.contentView);
- }];
- }
- #pragma mark - Property
- - (UIImageView *)bestSellerView {
- if (!_bestSellerView) {
- _bestSellerView = [UIImageView new];
- _bestSellerView.image = [UIImage imageNamed:@"amazonBestSeller"];
- }
- return _bestSellerView;
- }
- - (UILabel *)rankLabel {
- if (!_rankLabel) {
- _rankLabel = [UILabel new];
- _rankLabel.textColor = UIColorFromRGB(0xffffff);
- _rankLabel.font = [UIFont boldSystemFontOfSize:11];
- [_rankLabel setAdjustsFontSizeToFitWidth:YES];
- }
- return _rankLabel;
- }
- - (UILabel *)reviewCountLabel {
- if (!_reviewCountLabel) {
- _reviewCountLabel = [UILabel new];
- _reviewCountLabel.textColor = UIColorFromRGB(0xe77800);
- _reviewCountLabel.font = [UIFont systemFontOfSize:11];
- }
- return _reviewCountLabel;
- }
- - (UILabel *)amazonTitleLabel {
- if (!_amazonTitleLabel) {
- _amazonTitleLabel = [UILabel new];
- _amazonTitleLabel.textColor = UIColorFromRGB(0x333333);
- _amazonTitleLabel.font = [UIFont systemFontOfSize:11];
- _amazonTitleLabel.text = @"亚马逊评分";
- }
- return _amazonTitleLabel;
- }
- @end
|