1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// 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