123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- //
- // HomeTableViewCell.m
- // TheoryNetwork
- //
- // Created by tederen on 2019/9/26.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "HomeTableViewCell.h"
- #import "DocumentModel.h"
- #import "FLAnimatedImage.h"
- @interface HomeTableViewCell ()
- @property (weak, nonatomic) IBOutlet UILabel *titleLabel;
- @property (weak, nonatomic) IBOutlet UILabel *buninessLabel;
- @property (weak, nonatomic) IBOutlet UILabel *checkLabel;
- @property (weak, nonatomic) IBOutlet UIImageView *firstImgVi;
- @property (weak, nonatomic) IBOutlet UIImageView *secondImgVi;
- @property (weak, nonatomic) IBOutlet UIImageView *lastImgVi;
- @property (weak, nonatomic) IBOutlet UILabel *authorLab;
- @property (weak, nonatomic) IBOutlet UILabel *refereeLab;
- @property (weak, nonatomic) IBOutlet UIImageView *eyeImgV;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *rconst;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bconst;
- @end
- @implementation HomeTableViewCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- }
- + (instancetype)cellWithTableView:(UITableView *)tableView AndIndex:(NSInteger)index {
- NSLog(@"============================数组index%ld",(long)index);
- NSString *ID = @"HomeTableViewCell1";
- switch (index) {
- case 1:
- ID = @"HomeTableViewCell1";
- break;
- case 2:
- ID = @"HomeTableViewCell2";
- break;
- default:
- ID = @"HomeTableViewCell3";
- break;
- }
- HomeTableViewCell *cell = (HomeTableViewCell *)[tableView dequeueReusableCellWithIdentifier:ID];
- if (cell == nil || !cell) {
- cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeTableViewCell" owner:self options:nil] objectAtIndex:(index - 1)];
- }
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- return cell;
- }
- - (IBAction)deleteButtonClicked:(TDButton *)sender {
- if (self.buttonBlock) {
- self.buttonBlock();
- }
- }
- - (void)loadCurrentItemModel:(Item *)model{
- if (ISEmptyString(model.Title)) {
- _titleLabel.hidden = YES;
- }else{
- _titleLabel.attributedText = [self setTitleStr:model.Title isTop:model.IsTop];
- _titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
- }
- if (ISEmptyString(model.Source)) {
- self.bconst.constant = 0;
- _buninessLabel.hidden = YES;
- [self.eyeImgV mas_updateConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.titleLabel);
- }];
- }else{
- _buninessLabel.text = model.Source;
- }
- _checkLabel.text = [NSString stringWithFormat:@"%ld", (long)model.ReadCount];
- if (!ISEmptyNumber(model.Author)) {
- _authorLab.hidden = NO;
- _authorLab.text = model.Author;
- } else {
- _authorLab.hidden = YES;
- self.rconst.constant = 0;
- [self.refereeLab mas_updateConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.titleLabel);
- }];
- }
- _refereeLab.hidden = YES;
-
- if (model.ImageUrls.count >= 3) {
- if ([self isGifOrSwf:model.ImageUrls.firstObject]) {
- FLAnimatedImage * image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.ImageUrls.firstObject]]];
- FLAnimatedImageView * imageV = [[FLAnimatedImageView alloc] init];
- imageV.animatedImage = image;
- self.firstImgVi = imageV;
- }else{
- [self.firstImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls.firstObject] placeholder:IMG(@"img_placeHolder")];
- }
- if ([self isGifOrSwf:model.ImageUrls[1]]) {
- FLAnimatedImage * image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.ImageUrls[1]]]];
- FLAnimatedImageView * imageV = [[FLAnimatedImageView alloc] init];
- imageV.animatedImage = image;
- self.secondImgVi = imageV;
- }else{
- [self.secondImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls[1]] placeholder:IMG(@"img_placeHolder")];
- }
- if ([self isGifOrSwf:model.ImageUrls[2]]) {
- FLAnimatedImage * image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.ImageUrls[2]]]];
- FLAnimatedImageView * imageV = [[FLAnimatedImageView alloc] init];
- imageV.animatedImage = image;
- self.lastImgVi = imageV;
- }else{
- [self.lastImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls[2]] placeholder:IMG(@"img_placeHolder")];
- }
- // [self.secondImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls[1]] placeholder:IMG(@"img_placeHolder")];
- // [self.lastImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls[2]] placeholder:IMG(@"img_placeHolder")];
- self.firstImgVi.hidden = NO;
- self.lastImgVi.hidden = NO;
- self.secondImgVi.hidden = NO;
- }
- // else if (model.ImageUrls.count == 2) {
- // NSLog(@"%@",model.ImageUrls);
- // if ([model.ImageUrls.firstObject containsString:@"webp"]) {
- // [self.firstImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls.firstObject] placeholder:IMG(@"img_placeHolder")];
- // }else{
- // [self.firstImgVi sd_setImageWithURL: [NSURL URLWithString:model.ImageUrls.firstObject] placeholderImage:IMG(@"img_placeHolder")];
- // }
- //
- // [self.secondImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls[1]] placeholder:IMG(@"img_placeHolder")];
- // self.firstImgVi.hidden = NO;
- // self.lastImgVi.hidden = YES;
- // self.secondImgVi.hidden = NO;
- // }
- else{
- if ([self isGifOrSwf:model.ImageUrls.firstObject]) {
- FLAnimatedImage * image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.ImageUrls.firstObject]]];
- FLAnimatedImageView * imageV = [[FLAnimatedImageView alloc] init];
- imageV.animatedImage = image;
- self.firstImgVi = imageV;
- }else{
- [self.firstImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls.firstObject] placeholder:IMG(@"img_placeHolder")];
- }
- // [self.firstImgVi setImageWithURL:[NSURL URLWithString:model.ImageUrls.firstObject] placeholder:IMG(@"img_placeHolder")];
- self.firstImgVi.hidden = NO;
- self.lastImgVi.hidden = YES;
- self.secondImgVi.hidden = YES;
- }
- }
- - (NSMutableAttributedString *)setTitleStr:(NSString *)text isTop:(BOOL)isTop
- {
- NSMutableAttributedString * mattStr = [[NSMutableAttributedString alloc] init];
- // [mattStr addAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size:18],NSForegroundColorAttributeName: UIColorHex(000000)} range:NSMakeRange(0, text.length)];
- // NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
- // 行间距
- // [style setLineSpacing:8];
- // // 段落间距
- // [style setParagraphSpacing:6];
- // // 首行缩进
- // [style setFirstLineHeadIndent:25];
- // [mattStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)];
- if (isTop) {
- NSTextAttachment *imageAtta = [[NSTextAttachment alloc] init];
- imageAtta.bounds = CGRectMake(0, -2, 32, 15.5);
- imageAtta.image = [UIImage imageNamed:@"homeicon_setTop"];
- NSAttributedString *attach = [NSAttributedString attributedStringWithAttachment:imageAtta];
- [mattStr insertAttributedString:attach atIndex:0];
- [mattStr appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
- [mattStr appendAttributedString:[[NSAttributedString alloc] initWithString:text]];
- }else{
- [mattStr appendAttributedString:[[NSAttributedString alloc] initWithString:text]];
- }
- return mattStr;
- }
- - (BOOL)isGifOrSwf:(NSString *)imageStr
- {
- NSString * name = [[imageStr pathExtension] lowercaseString];
- if ([name hasSuffix:@"gif"] || [name hasSuffix:@"swf"]) {
- return YES;
- }else{
- return NO;
- }
- }
- @end
|