// // liveImageCell.m // ThePaperHD // // Created by scar1900 on 15/3/11. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "liveImageCell.h" #import "AsyncImageView.h" #define CONTENTWIDTH 1060/2 @interface liveImageCell(){ CGFloat descHeight; } @property(nonatomic, strong)imageObjectBO *imageBO; @property(nonatomic, strong)AsyncImageView *imgView; @property(nonatomic, strong)NSMutableArray *imageList; @property(nonatomic, strong)UIView *lineView; @property(nonatomic, strong)RTLabel *destLabel; @end @implementation liveImageCell @synthesize imageBO = _imageBO; @synthesize delegate; @synthesize dataDic = _dataDic; @synthesize imageList; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self.contentView addSubview:self.imgView]; [self.contentView addSubview:self.destLabel]; [self.contentView addSubview:self.lineView]; UITapGestureRecognizer *imageTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickImageHandler:)]; imageTap.numberOfTapsRequired = 1; [self addGestureRecognizer:imageTap]; [self.destLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.left).offset(10); make.right.equalTo(self.contentView.right).offset(-10); make.top.equalTo(self.imgView.bottom).offset(5); make.height.equalTo(@0); }]; } return self; } - (void)clickImageHandler:(UITapGestureRecognizer*)tap { if ([self.delegate respondsToSelector:@selector(clickImage:imageList:)]) { [self.delegate clickImage:self.imageBO imageList:self.imageList]; } } - (void)setDataDic:(NSDictionary *)dic { _dataDic = dic; self.imageList = [NSMutableArray array]; imageObjectBO *imgBO = dic[@"imageBO"]; self.imageBO = imgBO?imgBO:nil; NSArray *list = dic[@"imageList"]; if (list && list.count >0) { [list enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { imageObjectBO *imgBOInList = setJsonDicToDataModel(obj, [imageObjectBO class]); [self.imageList addObject:imgBOInList]; }]; } NSString *type = dic[@"type"]; if ([type isMatchedByRegex:@"top"]) { self.lineView.hidden = YES; }else self.lineView.hidden = NO; [self setLayoutSub]; } - (void)setImageBO:(imageObjectBO *)data { _imageBO = data; self.imgView.imageUrl = data.url; if (isBlankString(data.desc)) { self.destLabel.hidden = YES; descHeight = 0; self.destLabel.text = @""; }else { self.destLabel.hidden = NO; descHeight = returnTextHeightWithRTLabel(data.desc, CONTENTWIDTH, appFont(imageDescFontSize, NO), 8); self.destLabel.text = data.desc; } [self.destLabel setNeedsDisplay]; // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(DISPATCH_QUEUE_PRIORITY_DEFAULT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // // }); } - (AsyncImageView*)imgView { if (!_imgView) { _imgView = [[AsyncImageView alloc]initWithFrame:CGRectZero]; _imgView.backgroundColor = [UIColor clearColor]; _imgView.hidden = YES; } return _imgView; } - (UIView*)lineView { if (!_lineView) { _lineView = [[UIView alloc]initWithFrame:CGRectZero]; _lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _lineView; } - (RTLabel*)destLabel { if (!_destLabel) { _destLabel = [[RTLabel alloc]initWithFrame:CGRectZero]; _destLabel.backgroundColor = [UIColor clearColor]; _destLabel.textAlignment = RTTextAlignmentCenter; _destLabel.textColor = [UIColor colorWithHexString:ImageSpeakDesc]; _destLabel.lineBreakMode = RTTextLineBreakModeWordWrapping; _destLabel.lineSpacing = 8; } _destLabel.font = appFont(imageDescFontSize, NO); return _destLabel; } - (void) setLayoutSub{ CGFloat padding = 0; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { padding = 125; } CGSize imageSize = CGSizeMake([self.imageBO.width floatValue], [self.imageBO.height floatValue]); CGSize size = CGSizeZero; if (imageSize.width > CONTENTWIDTH) { size = CGSizeMake(CONTENTWIDTH, imageSize.height*CONTENTWIDTH/imageSize.width); }else if(imageSize.width >=480 && imageSize.width <= 530){ size = CGSizeMake([self.imageBO.width floatValue], [self.imageBO.height floatValue]); }else{ size = CGSizeMake([self.imageBO.width floatValue]*1.1, [self.imageBO.height floatValue]*1.1); } [self.imgView remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.left).offset(226/2+CONTENTWIDTH/2-size.width/2+padding); make.width.equalTo(size.width); make.top.equalTo(self.contentView.top); make.height.equalTo(size.height); }]; [self.destLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.left).offset(padding+226/2); make.width.mas_equalTo(CONTENTWIDTH); make.top.equalTo(self.imgView.bottom).offset(5); make.height.mas_equalTo(descHeight); }]; [self.lineView remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.left).offset(padding+7); make.width.equalTo(1); make.top.equalTo(self.top); make.bottom.equalTo(self.bottom); }]; if (self.imgView.hidden) { self.imgView.hidden = NO; } } - (void)awakeFromNib { // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end