小说绘上架版本
This commit is contained in:
+24
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// YJBannerViewCell.h
|
||||
// YJBannerViewDemo
|
||||
//
|
||||
// Created by YJHou on 2015/5/24.
|
||||
// Copyright © 2015年 Address:https://github.com/stackhou . All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface YJBannerViewCell : UICollectionViewCell
|
||||
|
||||
@property (nonatomic, strong) UIColor *titleLabelTextColor;
|
||||
@property (nonatomic, strong) UIFont *titleLabelTextFont;
|
||||
@property (nonatomic, strong) UIColor *titleLabelBackgroundColor;
|
||||
@property (nonatomic, assign) CGFloat titleLabelHeight;
|
||||
@property (nonatomic, assign) CGFloat titleLabelEdgeMargin;
|
||||
@property (nonatomic, assign) NSTextAlignment titleLabelTextAlignment;
|
||||
@property (nonatomic, assign) UIViewContentMode showImageViewContentMode; /**< 填充样式 默认UIViewContentModeScaleToFill */
|
||||
@property (nonatomic, assign) BOOL isConfigured;
|
||||
|
||||
- (void)cellWithSelectorString:(NSString *)selectorString imagePath:(NSString *)imagePath placeholderImage:(UIImage *)placeholderImage title:(NSString *)title;
|
||||
|
||||
@end
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
//
|
||||
// YJBannerViewCell.m
|
||||
// YJBannerViewDemo
|
||||
//
|
||||
// Created by YJHou on 2015/5/24.
|
||||
// Copyright © 2015年 Address:https://github.com/stackhou . All rights reserved.
|
||||
//
|
||||
|
||||
#import "YJBannerViewCell.h"
|
||||
#import "UIView+YJBannerViewExt.h"
|
||||
|
||||
@interface YJBannerViewCell ()
|
||||
|
||||
@property (nonatomic, strong) UIImageView *showImageView; /**< 显示图片 */
|
||||
@property (nonatomic, strong) UILabel *titleLabel; /**< 标题头 */
|
||||
@property (nonatomic, strong) UIView *titleLabelBgView; /**< 标题背景 */
|
||||
|
||||
@end
|
||||
|
||||
@implementation YJBannerViewCell
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
[self _setUpMainView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)_setUpMainView{
|
||||
[self.contentView addSubview:self.showImageView];
|
||||
[self.contentView addSubview:self.titleLabelBgView];
|
||||
[self.contentView addSubview:self.titleLabel];
|
||||
}
|
||||
|
||||
#pragma mark - Setter && Getter
|
||||
- (void)setTitleLabelBackgroundColor:(UIColor *)titleLabelBackgroundColor{
|
||||
_titleLabelBackgroundColor = titleLabelBackgroundColor;
|
||||
self.titleLabelBgView.backgroundColor = titleLabelBackgroundColor;
|
||||
}
|
||||
|
||||
- (void)setTitleLabelTextColor:(UIColor *)titleLabelTextColor{
|
||||
_titleLabelTextColor = titleLabelTextColor;
|
||||
self.titleLabel.textColor = titleLabelTextColor;
|
||||
}
|
||||
|
||||
- (void)setTitleLabelTextFont:(UIFont *)titleLabelTextFont{
|
||||
_titleLabelTextFont = titleLabelTextFont;
|
||||
self.titleLabel.font = titleLabelTextFont;
|
||||
}
|
||||
|
||||
-(void)setTitleLabelTextAlignment:(NSTextAlignment)titleLabelTextAlignment{
|
||||
_titleLabelTextAlignment = titleLabelTextAlignment;
|
||||
self.titleLabel.textAlignment = titleLabelTextAlignment;
|
||||
}
|
||||
|
||||
- (void)setShowImageViewContentMode:(UIViewContentMode)showImageViewContentMode{
|
||||
_showImageViewContentMode = showImageViewContentMode;
|
||||
self.showImageView.contentMode = showImageViewContentMode;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews{
|
||||
[super layoutSubviews];
|
||||
|
||||
CGFloat titleBgViewlH = self.titleLabelHeight;
|
||||
self.showImageView.frame = self.bounds;
|
||||
|
||||
CGFloat titlBgViewX = 0.0f;
|
||||
CGFloat titleBgViewY = self.height_bannerView - titleBgViewlH;
|
||||
CGFloat titleBgViewW = self.width_bannerView - 2 * titlBgViewX;
|
||||
_titleLabelBgView.frame = CGRectMake(titlBgViewX, titleBgViewY, titleBgViewW, titleBgViewlH);
|
||||
|
||||
CGFloat titleLabelH = titleBgViewlH;
|
||||
CGFloat titleLabelX = self.titleLabelEdgeMargin;
|
||||
CGFloat titleLabelY = titleBgViewY;
|
||||
CGFloat titleLabelW = self.width_bannerView - 2 * titleLabelX;
|
||||
_titleLabel.frame = CGRectMake(titleLabelX, titleLabelY, titleLabelW, titleLabelH);
|
||||
}
|
||||
|
||||
#pragma mark - 刷新数据
|
||||
- (void)cellWithSelectorString:(NSString *)selectorString imagePath:(NSString *)imagePath placeholderImage:(UIImage *)placeholderImage title:(NSString *)title{
|
||||
|
||||
if (imagePath) {
|
||||
self.showImageView.hidden = NO;
|
||||
if ([imagePath isKindOfClass:[NSString class]]) {
|
||||
if ([imagePath hasPrefix:@"http"]) {
|
||||
|
||||
// 检验方法是否可用
|
||||
SEL selector = NSSelectorFromString(selectorString);
|
||||
if ([self.showImageView respondsToSelector:selector]) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
|
||||
[self.showImageView performSelector:selector withObject:[NSURL URLWithString:imagePath] withObject:placeholderImage];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
} else {
|
||||
if (imagePath.length > 0) {
|
||||
UIImage *image = [UIImage imageNamed:imagePath];
|
||||
if (!image) {
|
||||
image = [UIImage imageWithContentsOfFile:imagePath];
|
||||
}
|
||||
self.showImageView.image = image;
|
||||
}
|
||||
}
|
||||
} else if ([imagePath isKindOfClass:[UIImage class]]) {
|
||||
self.showImageView.image = (UIImage *)imagePath;
|
||||
}else{
|
||||
self.showImageView.image = placeholderImage;
|
||||
}
|
||||
}else{
|
||||
self.showImageView.hidden = YES;
|
||||
}
|
||||
|
||||
if (title.length > 0) {
|
||||
self.titleLabel.text = title;
|
||||
self.titleLabel.hidden = NO;
|
||||
self.titleLabelBgView.hidden = NO;
|
||||
}else{
|
||||
self.titleLabel.hidden = YES;
|
||||
self.titleLabelBgView.hidden = YES;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Lazy
|
||||
- (UIImageView *)showImageView{
|
||||
if (!_showImageView) {
|
||||
_showImageView = [[UIImageView alloc] init];
|
||||
}
|
||||
return _showImageView;
|
||||
}
|
||||
|
||||
- (UILabel *)titleLabel{
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [[UILabel alloc] init];
|
||||
_titleLabel.hidden = YES;
|
||||
_titleLabel.backgroundColor = [UIColor clearColor];
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
|
||||
- (UIView *)titleLabelBgView{
|
||||
if (!_titleLabelBgView) {
|
||||
_titleLabelBgView = [[UIView alloc] init];
|
||||
_titleLabelBgView.hidden = YES;
|
||||
}
|
||||
return _titleLabelBgView;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// YJBannerViewCollectionView.h
|
||||
// YJBannerViewDemo
|
||||
//
|
||||
// Created by YJHou on 2017/11/21.
|
||||
// Copyright © 2017年 Address:https://github.com/stackhou . All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface YJBannerViewCollectionView : UICollectionView <UIGestureRecognizerDelegate>
|
||||
|
||||
@end
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// YJBannerViewCollectionView.m
|
||||
// YJBannerViewDemo
|
||||
//
|
||||
// Created by YJHou on 2017/11/21.
|
||||
// Copyright © 2017年 Address:https://github.com/stackhou . All rights reserved.
|
||||
//
|
||||
|
||||
#import "YJBannerViewCollectionView.h"
|
||||
|
||||
@implementation YJBannerViewCollectionView
|
||||
|
||||
@end
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// YJBannerViewFooter.h
|
||||
// YJBannerViewDemo
|
||||
//
|
||||
// Created by YJHou on 2015/5/24.
|
||||
// Copyright © 2015年 Address:https://github.com/stackhou . All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
typedef NS_ENUM(NSInteger, YJBannerViewStatus) {
|
||||
YJBannerViewStatusIdle = 0, // 闲置
|
||||
YJBannerViewStatusTrigger // 触发
|
||||
};
|
||||
|
||||
@interface YJBannerViewFooter : UICollectionReusableView
|
||||
|
||||
@property (nonatomic, assign) YJBannerViewStatus state;
|
||||
|
||||
@property (nonatomic, strong) UIFont *footerTitleFont;
|
||||
@property (nonatomic, strong) UIColor *footerTitleColor;
|
||||
@property (nonatomic, copy) NSString *IndicateImageName; /**< 指示图片的名字 */
|
||||
@property (nonatomic, copy) NSString *idleTitle; /**< 闲置 */
|
||||
@property (nonatomic, copy) NSString *triggerTitle; /**< 触发 */
|
||||
|
||||
@end
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
//
|
||||
// YJBannerViewFooter.m
|
||||
// YJBannerViewDemo
|
||||
//
|
||||
// Created by YJHou on 2015/5/24.
|
||||
// Copyright © 2015年 Address:https://github.com/stackhou . All rights reserved.
|
||||
//
|
||||
|
||||
#import "YJBannerViewFooter.h"
|
||||
|
||||
#define YJ_ARROW_SIZE 15.0f
|
||||
|
||||
@interface YJBannerViewFooter ()
|
||||
|
||||
@property (nonatomic, strong) UIImageView *arrowView;
|
||||
@property (nonatomic, strong) UILabel *label;
|
||||
|
||||
@end
|
||||
|
||||
@implementation YJBannerViewFooter
|
||||
|
||||
@synthesize idleTitle = _idleTitle;
|
||||
@synthesize triggerTitle = _triggerTitle;
|
||||
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self addSubview:self.arrowView];
|
||||
[self addSubview:self.label];
|
||||
|
||||
self.state = YJBannerViewStatusIdle;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews{
|
||||
[super layoutSubviews];
|
||||
|
||||
CGFloat arrowX = self.bounds.size.width * 0.5 - YJ_ARROW_SIZE - 2.5;
|
||||
CGFloat arrowY = (self.bounds.size.height - YJ_ARROW_SIZE) * 0.5;
|
||||
CGFloat arrowW = YJ_ARROW_SIZE;
|
||||
CGFloat arrowH = YJ_ARROW_SIZE;
|
||||
self.arrowView.frame = CGRectMake(arrowX, arrowY, arrowW, arrowH);
|
||||
|
||||
CGFloat labelX = self.bounds.size.width * 0.5 + 2.5;
|
||||
CGFloat labelY = 0;
|
||||
CGFloat labelW = YJ_ARROW_SIZE;
|
||||
CGFloat labelH = self.bounds.size.height;
|
||||
self.label.frame = CGRectMake(labelX, labelY, labelW, labelH);
|
||||
}
|
||||
|
||||
#pragma mark - setters & getters
|
||||
- (void)setState:(YJBannerViewStatus)state{
|
||||
_state = state;
|
||||
|
||||
switch (state) {
|
||||
case YJBannerViewStatusIdle:{
|
||||
self.label.text = self.idleTitle;
|
||||
[UIView animateWithDuration:0.25 animations:^{
|
||||
self.arrowView.transform = CGAffineTransformMakeRotation(0);
|
||||
}];
|
||||
}
|
||||
break;
|
||||
case YJBannerViewStatusTrigger:{
|
||||
self.label.text = self.triggerTitle;
|
||||
[UIView animateWithDuration:0.25 animations:^{
|
||||
self.arrowView.transform = CGAffineTransformMakeRotation(M_PI);
|
||||
}];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Setter
|
||||
- (void)setFooterTitleFont:(UIFont *)footerTitleFont{
|
||||
_footerTitleFont = footerTitleFont;
|
||||
self.label.font = _footerTitleFont;
|
||||
}
|
||||
|
||||
- (void)setFooterTitleColor:(UIColor *)footerTitleColor{
|
||||
_footerTitleColor = footerTitleColor;
|
||||
self.label.textColor = _footerTitleColor;
|
||||
}
|
||||
|
||||
- (void)setIndicateImageName:(NSString *)IndicateImageName{
|
||||
_IndicateImageName = IndicateImageName;
|
||||
if (_IndicateImageName.length > 0 && self.arrowView.image == nil) {
|
||||
self.arrowView.image = [UIImage imageNamed:_IndicateImageName];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Lazy
|
||||
- (UIImageView *)arrowView{
|
||||
if (!_arrowView) {
|
||||
_arrowView = [[UIImageView alloc] init];
|
||||
}
|
||||
return _arrowView;
|
||||
}
|
||||
|
||||
- (UILabel *)label{
|
||||
if (!_label) {
|
||||
_label = [[UILabel alloc] init];
|
||||
_label.numberOfLines = 0;
|
||||
}
|
||||
return _label;
|
||||
}
|
||||
|
||||
- (void)setIdleTitle:(NSString *)idleTitle{
|
||||
_idleTitle = idleTitle;
|
||||
if (self.state == YJBannerViewStatusIdle) {
|
||||
self.label.text = idleTitle;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setTriggerTitle:(NSString *)triggerTitle{
|
||||
_triggerTitle = triggerTitle;
|
||||
if (self.state == YJBannerViewStatusTrigger) {
|
||||
self.label.text = triggerTitle;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// YJMallCollectionViewCell.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2019/5/28.
|
||||
// Copyright © 2019 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface YJMallCollectionViewCell : UICollectionViewCell
|
||||
|
||||
@property (nonatomic, strong) TFBannerModel *bannerModel;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// YJMallCollectionViewCell.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2019/5/28.
|
||||
// Copyright © 2019 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "YJMallCollectionViewCell.h"
|
||||
#import "UIView+AZGradient.h"
|
||||
|
||||
@implementation YJMallCollectionViewCell
|
||||
{
|
||||
UIImageView *backHoldImageView;
|
||||
UIView *backFrostedGlassView;
|
||||
|
||||
YYAnimatedImageView *bannerImageView;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
[self createSubViews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)createSubViews
|
||||
{
|
||||
backHoldImageView = [[UIImageView alloc] init];
|
||||
backHoldImageView.clipsToBounds = YES;
|
||||
backHoldImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
[self addSubview:backHoldImageView];
|
||||
|
||||
[backHoldImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(self);
|
||||
}];
|
||||
|
||||
backFrostedGlassView = [[UIView alloc] init];
|
||||
[self addSubview:backFrostedGlassView];
|
||||
|
||||
[backFrostedGlassView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(self);
|
||||
}];
|
||||
|
||||
bannerImageView = [[YYAnimatedImageView alloc] init];
|
||||
bannerImageView.layer.cornerRadius = 4;
|
||||
bannerImageView.clipsToBounds = YES;
|
||||
bannerImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
[self addSubview:bannerImageView];
|
||||
|
||||
[bannerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(kHalfMargin + kQuarterMargin);
|
||||
make.bottom.mas_equalTo(self.mas_bottom);
|
||||
make.width.mas_equalTo(SCREEN_WIDTH - 2 * (kHalfMargin + kQuarterMargin));
|
||||
make.height.mas_equalTo(kGeometricHeight((SCREEN_WIDTH - 2 * (kHalfMargin + kQuarterMargin)), 5, 3));
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (void)setBannerModel:(TFBannerModel *)bannerModel
|
||||
{
|
||||
_bannerModel = bannerModel;
|
||||
|
||||
if (!bannerModel) {
|
||||
return;
|
||||
}
|
||||
@try {
|
||||
[[YYWebImageManager sharedManager] requestImageWithURL:[NSURL URLWithString:bannerModel.image?:@""] options:YYWebImageOptionSetImageWithFadeAnimation progress:nil transform:nil completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self->backHoldImageView.image = image;
|
||||
[self->backFrostedGlassView az_setGradientBackgroundWithColors:@[[UIColor whiteColor], [[UIColor colorWithHexString:bannerModel.color?:@"#000000"] colorWithAlphaComponent:0.8]] locations:nil startPoint:CGPointMake(1.0, 1.0) endPoint:CGPointMake(1.0, 0.0)];
|
||||
|
||||
});
|
||||
}];
|
||||
} @catch (NSException *exception) {
|
||||
|
||||
} @finally {
|
||||
|
||||
}
|
||||
|
||||
[bannerImageView setImageWithURL:[NSURL URLWithString:bannerModel.image?:@""] placeholder:HoldImage options:YYWebImageOptionSetImageWithFadeAnimation completion:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user