You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.7 KiB
101 lines
3.7 KiB
4 years ago
|
//
|
||
|
// TFDiscoverComicAdvertisementCell.m
|
||
|
// TFReader
|
||
|
//
|
||
|
// Created by 谢腾飞 on 2020/12/16.
|
||
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "TFDiscoverComicAdvertisementCell.h"
|
||
|
#import "TFAdvertisementManager.h"
|
||
|
|
||
|
@interface TFDiscoverComicAdvertisementCell ()
|
||
|
|
||
|
@property (nonatomic ,strong) TFAdvertModel *advertModel;
|
||
|
@property (nonatomic ,weak) TFAdvertisementManager *adView;
|
||
|
@property (nonatomic ,weak) UILabel *titleLabel;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation TFDiscoverComicAdvertisementCell
|
||
|
|
||
|
- (void)createSubviews
|
||
|
{
|
||
|
[super createSubviews];
|
||
|
|
||
|
TFAdvertisementManager *adView = [[TFAdvertisementManager alloc] initWithFrame:CGRectMake(kHalfMargin, kHalfMargin, SCREEN_WIDTH - kMargin, (SCREEN_WIDTH - 2 * kHalfMargin) / 2) advertisementType:TFAdvertisementTypeNone advertisementPosition:TFAdvertisementPositionNone];
|
||
|
self.adView = adView;
|
||
|
__weak typeof(adView) weakView = adView;
|
||
|
WS(weakSelf)
|
||
|
adView.closeBlock = ^{
|
||
|
[weakView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.height.mas_equalTo(1.0);
|
||
|
make.top.equalTo(self.contentView);
|
||
|
}];
|
||
|
[weakSelf.mainTableView reloadData];
|
||
|
};
|
||
|
adView.userInteractionEnabled = YES;
|
||
|
adView.layer.cornerRadius = 8.0f;
|
||
|
[self.contentView addSubview:adView];
|
||
|
[adView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kHalfMargin);
|
||
|
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kHalfMargin);
|
||
|
make.width.mas_equalTo(SCREEN_WIDTH - kMargin);
|
||
|
make.height.mas_equalTo(kGeometricHeight(SCREEN_WIDTH - kMargin, 7, 4));
|
||
|
}];
|
||
|
|
||
|
UILabel *titleLabel = [[UILabel alloc] init];
|
||
|
self.titleLabel = titleLabel;
|
||
|
titleLabel.textColor = kBlackColor;
|
||
|
titleLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
titleLabel.font = kMainFont;
|
||
|
[self.contentView addSubview:titleLabel];
|
||
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(kHalfMargin);
|
||
|
make.top.mas_equalTo(adView.mas_bottom).with.offset(kHalfMargin);
|
||
|
make.height.mas_equalTo(kMargin);
|
||
|
make.right.mas_equalTo(self.contentView.mas_right);
|
||
|
}];
|
||
|
|
||
|
UIView *splitLine = [[UIView alloc] init];
|
||
|
splitLine.backgroundColor = [UIColor clearColor];
|
||
|
[self.contentView addSubview:splitLine];
|
||
|
[splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.top.equalTo(titleLabel.mas_bottom).priorityLow();
|
||
|
make.left.right.bottom.equalTo(self.contentView);
|
||
|
make.height.mas_equalTo(0.1);
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
- (void)setAdModel:(TFAdvertModel * _Nonnull)adModel refresh:(BOOL)refresh
|
||
|
{
|
||
|
if (refresh || (adModel.advert_id != _advertModel.advert_id)) {
|
||
|
adModel.ad_width = CGRectGetWidth(self.contentView.bounds);
|
||
|
adModel.ad_height = CGRectGetHeight(self.contentView.bounds);
|
||
|
|
||
|
_advertModel = adModel;
|
||
|
|
||
|
self.adView.advertModel = adModel;
|
||
|
if (adModel.ad_type == 1) {
|
||
|
[self.adView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.height.mas_equalTo((SCREEN_WIDTH - 2 * kHalfMargin) / 2.0);
|
||
|
}];
|
||
|
} else {
|
||
|
[self.adView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.height.mas_equalTo((SCREEN_WIDTH - 2 * kHalfMargin) * 1.0 / 3.0);
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
self.titleLabel.text = adModel.ad_title ?: @"";
|
||
|
[self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
if (self.titleLabel.text.length == 0 || adModel.ad_type == 2) {
|
||
|
make.height.mas_equalTo(CGFLOAT_MIN);
|
||
|
} else {
|
||
|
make.height.mas_equalTo(kMargin);
|
||
|
}
|
||
|
}];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@end
|