123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- //
- // PdProductShowCell.m
- // FirstLink
- //
- // Created by jack on 15/7/17.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "PdProductShowCell.h"
- #import "ProductShowItem.h"
- #import "FKProDetailViewModel.h"
- @implementation PdProductShowCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self initialize];
- }
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- return self;
- }
- - (void)initialize {
- [self.contentView addSubview:self.showImgView];
- [self.contentView addSubview:self.contentLabel];
- self.contentView.backgroundColor = [UIColor clearColor];
-
- [self.showImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView);
- make.centerX.equalTo(self.contentView);
- make.width.mas_equalTo([PdProductShowCell defaultImgWidth]);
- make.height.mas_equalTo([PdProductShowCell defaultImgHeight]);
- }];
-
- [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(15);
- make.right.equalTo(self.contentView).offset(- 15);
- make.bottom.equalTo(self.contentView).offset(- 15);
- }];
-
- }
- - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
- if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) {
- FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel;
- ProductShowItem *showItem = [detailModel.dataItem productShowItemForIndex:indexPath.row];
-
- [self configWithShowItem:showItem];
- }
- }
- - (void)configWithShowItem:(ProductShowItem *)item{
-
- if (item) {
- self.showImgView.image = nil;
-
- [self.showImgView setImageWithURL:item.imageUrl cdnWidth:[item realImgSize].width];
- self.imgHeightCtrl.constant = [item realImgSize].height;
- self.imgWidthCtrl.constant = [item realImgSize].width;
- self.contentLabel.attributedText = [FLStringHelper attStringWithText:item.describString lineSpace:2.4f];
- }
- }
- + (CGFloat)defaultImgHeight {
- return [self defaultImgWidth] * 9.0f / 7.0f;
- }
- + (CGFloat)defaultImgWidth {
- return UISCREENWIDTH - 20;
- }
- + (CGFloat)cellHeightForText:(NSString *)text withImgHeight:(CGFloat)imgHeight {
- // CGFloat imgH = imgHeight ? imgHeight : [PdProductShowCell imgViewHeigth];
- if (text.length == 0) {
- return (imgHeight + 10);
- }
-
- CGFloat textWidth = [UIScreen mainScreen].bounds.size.width - 15 * 2;
- NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc]init];
- paraStyle.lineSpacing = 2.4f;
- NSDictionary *dict = @{NSFontAttributeName : [UIFont systemFontOfSize:14], NSParagraphStyleAttributeName : paraStyle};
- CGRect rect = [text boundingRectWithSize:CGSizeMake(textWidth, 0)
- options:NSStringDrawingUsesLineFragmentOrigin
- attributes:dict
- context:nil];
-
- return imgHeight + 15 * 2 + rect.size.height;
- }
- #pragma mark - action
- - (void)clickImgView{
- if ([self.delegate respondsToSelector:@selector(clickProductImg:)]) {
- [self.delegate clickProductImg:self];
- }
- }
- //#pragma mark - Function
- //
- //- (void)configCell:(id)obj {
- // if ([obj isKindOfClass:[ProductShowItem class]]) {
- // ProductShowItem *item = (ProductShowItem *)obj;
- //
- // self.showImgView.image = nil;
- // [self.showImgView setImageWithURL:[NSURL URLWithString:item.imageUrl]];
- // self.imgHeightCtrl.constant = [item realImgSize].height;
- // self.imgWidthCtrl.constant = [item realImgSize].width;
- // self.contentLabel.attributedText = [FLStringHelper attStringWithText:item.describString
- // lineSpace:2.4f];
- // }
- //}
- #pragma mark - getter && setter
- - (UIImageView *)showImgView
- {
- if (_showImgView == nil) {
- _showImgView = [[UIImageView alloc]init];
- _showImgView.userInteractionEnabled = YES;
- _showImgView.contentMode = UIViewContentModeScaleAspectFit;
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickImgView)];
- [_showImgView addGestureRecognizer:tap];
- }
- return _showImgView;
- }
- - (UILabel *)contentLabel
- {
- if (_contentLabel == nil) {
- _contentLabel = [[UILabel alloc]init];
- _contentLabel.backgroundColor = [UIColor clearColor];
- _contentLabel.numberOfLines = 0;
- _contentLabel.textAlignment = NSTextAlignmentLeft;
- _contentLabel.textColor = UIColorFromRGB(0x666666);
- _contentLabel.font = [UIFont systemFontOfSize:14];
- _contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
- }
- return _contentLabel;
- }
- - (NSLayoutConstraint *)imgHeightCtrl
- {
- if (_imgHeightCtrl == nil) {
- for (NSLayoutConstraint *constraint in self.showImgView.constraints) {
- if (constraint.firstItem == self.showImgView && constraint.firstAttribute == NSLayoutAttributeHeight){
- _imgHeightCtrl = constraint;
- break;
- }
- }
- }
- return _imgHeightCtrl;
- }
- - (NSLayoutConstraint *)imgWidthCtrl
- {
- if (_imgWidthCtrl == nil) {
- for (NSLayoutConstraint *constraint in self.showImgView.constraints) {
- if (constraint.firstItem == self.showImgView && constraint.firstAttribute == NSLayoutAttributeWidth){
- _imgWidthCtrl = constraint;
- break;
- }
- }
- }
- return _imgWidthCtrl;
- }
- @end
|