al
liurenjie
2021-07-03 1b73d5d0b495f2d643c2523e1b8399f925b4f702
BuWanVideo2.0/Recommend/Recommend/Cell/RecommendTwoColumnCell.m
@@ -7,6 +7,7 @@
//
#import "RecommendTwoColumnCell.h"
#define BSKPlaceHolderImage [UIImage imageNamed:@"默认加载图片"]
@interface RecommendTwoColumnCell ()
@@ -48,31 +49,41 @@
- (void)setData:(NSDictionary *)data {
    _data = data;
    if (data) {
        [_imaegView setYthImageWithURL:data[@"Hpicture"] placeholderImage:nil];
        self.labelTag.text = data[@"Tag"];
        if (data[@"Score"]) {
            NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@分",data[@"Score"]]];
            NSRange range1 = [[NSString stringWithFormat:@"%@分",data[@"Score"]] rangeOfString:@"."];
            NSRange range2 = NSMakeRange(range1.location+1, 2);
            [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:9] range:range2];
            [ self.labelScore setAttributedText:noteStr];
        }
        NSString *conetnt = data[@"Name"];
        self.labelTitle.text = conetnt;
        self.labelTitle.numberOfLines = 2;
        CGFloat height = [self fetchLabelHeight:conetnt fontSize:14 width:(KScreenW - 9 - 8 - 9) / 2];
        if (height > 34) {
            height = 34;
        }
        self.labelTitle.sd_resetLayout.leftSpaceToView(self.contentView, 0).topSpaceToView(self.imaegView, 6).rightSpaceToView(self.contentView, 0).heightIs(height);
        [self laodata:data];
    }
}
- (void)setDataNormol:(NSDictionary *)dataNormol {
    if (_dataNormol) {
        [self laodata:dataNormol];
    }
}
- (void)laodata:(NSDictionary *)data {
    [_imaegView setYthImageWithURL:data[@"Hpicture"] placeholderImage:BSKPlaceHolderImage];
    self.labelTag.text = data[@"Tag"];
    if (data[@"Score"]) {
        NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@分",data[@"Score"]]];
        NSRange range1 = [[NSString stringWithFormat:@"%@分",data[@"Score"]] rangeOfString:@"."];
        NSRange range2 = NSMakeRange(range1.location+1, 2);
        [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:9] range:range2];
        [ self.labelScore setAttributedText:noteStr];
    }
    NSString *conetnt = data[@"Name"];
    self.labelTitle.text = conetnt;
    self.labelTitle.numberOfLines = 2;
    CGFloat height = [self fetchLabelHeight:conetnt fontSize:14 width:(KScreenW - 9 - 8 - 9) / 2];
    if (height > 34) {
        height = 34;
    }
    self.labelTitle.sd_resetLayout.leftSpaceToView(self.contentView, 0).topSpaceToView(self.imaegView, 6).rightSpaceToView(self.contentView, 0).heightIs(height);
}
- (CGFloat)fetchLabelHeight:(NSString *)string fontSize:(NSInteger)fontSize width:(float)width {
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]};
    CGRect rect =  [string boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin |