// // KWMBlogCell.m // iCemarose // // Created by HouWeiBin on 16/8/24. // Copyright © 2016年 kollway. All rights reserved. // #import "KWMBlogCell.h" #import "KWMImageUtil.h" #import <SDWebImage/UIImageView+WebCache.h> @implementation KWMBlogCell - (void)awakeFromNib { [super awakeFromNib]; [self initView]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } -(void)initView{ CGFloat imageHeight = 211.0/375.0 * UI_SCREEN_WIDTH; self.imageHeight.constant = imageHeight; } -(void)setData:(NSInteger)position{ self.headerHeight.constant = 0; // if(position == 0){ // self.headerHeight.constant = 15; // }else{ // self.headerHeight.constant = 0; // } } - (void)setArticle:(KWMArticlesResult *)article{ _article = article; NSString *str = [self filterHTML:article.body_html]; self.lbContent.text = str; self.lbTitle.text = article.title; if (article.imageScr == nil) { self.imageHeight.constant = 0; }else{ NSString *imageString = [KWMImageUtil getProductImageUrlByOriginalUrl:article.imageScr ImageSize:NormalImage]; NSURL *imageURL = [NSURL URLWithString:imageString]; [self.ivImg sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@"ic_loading_big"]]; } } //解析html数据 -(NSString *)filterHTML:(NSString *)html { NSScanner * scanner = [NSScanner scannerWithString:html]; NSString * text = nil; while([scanner isAtEnd]==NO) { //找到标签的起始位置 [scanner scanUpToString:@"<" intoString:nil]; //找到标签的结束位置 [scanner scanUpToString:@">" intoString:&text]; //替换字符 html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>",text] withString:@""]; } // NSString * regEx = @"<([^>]*)>"; html = [html stringByReplacingOccurrencesOfString:@"\n" withString:@""]; return html; } @end