小说绘上架版本

This commit is contained in:
xtfei2011
2021-02-07 11:24:08 +08:00
commit ee5c1c8b12
1762 changed files with 115892 additions and 0 deletions
@@ -0,0 +1,24 @@
//
// TFShareBodyModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/5.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFShareBodyModel : NSObject
@property (nonatomic ,copy) NSString *title;
@property (nonatomic ,copy) NSString *desc;
@property (nonatomic ,copy) NSString *imageUrl;
@property (nonatomic ,copy) NSString *shareUrl;
@property (nonatomic ,strong) UIImage *shareImage;
@property (nonatomic ,copy) NSString *error;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,48 @@
//
// TFShareBodyModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/5.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFShareBodyModel.h"
@implementation TFShareBodyModel
- (void)setShareUrl:(NSString *)shareUrl
{
_shareUrl = shareUrl;
if (!kObjectIsEmpty(shareUrl)) {
[[YYWebImageManager sharedManager] requestImageWithURL:[NSURL URLWithString:shareUrl] options:kNilOptions progress:nil transform:nil completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
self.shareImage = image;
}];
}
}
- (UIImage *)shareImage
{
if (!_shareImage) {
_shareImage = [UIImage imageNamed:[[[[NSBundle mainBundle] infoDictionary] valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject]];
}
return _shareImage;
}
- (NSString *)title
{
if (!_title) {
_title = App_Name;
}
return _title;
}
- (NSString *)desc
{
if (!_desc) {
_desc = [NSString stringWithFormat:@"%@ - %@%@", App_Name, TFLocalizedString(@"分享得"), TFSystemInfoManager.masterUnit];
}
return _desc;
}
@end
@@ -0,0 +1,33 @@
//
// TFShareManager.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/5.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "TFShareView.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFShareManager : NSObject
/// 分享作品
/// @param production_id 作品ID
/// @param chapter_id 章节ID
/// @param type 分享类型
+ (void)shareWithProduction_id:(NSString *)production_id chapter_id:(NSString * _Nullable)chapter_id type:(TFShareType)type;
/// 分享APP
+ (void)shareApp;
/// 自定义分享
/// @param title 分享标题
/// @param desc 分享描述
/// @param imageUrl 分享图片链接
/// @param shareUrl 分享链接
+ (void)shareWithTitle:(NSString *)title desc:(NSString *)desc imageUrl:(NSString *)imageUrl shareUrl:(NSString *)shareUrl;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,232 @@
//
// TFShareManager.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/5.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFShareManager.h"
#import "TFShareView.h"
#import "TFShareModel.h"
#import "TFShareBodyModel.h"
#if __has_include(<UMShare/UMShare.h>)
#import <UMShare/UMShare.h>
#endif
#import <ShareSDK/ShareSDK.h>
@implementation TFShareManager
+ (void)shareWithProduction_id:(NSString *)production_id chapter_id:(NSString * _Nullable)chapter_id type:(TFShareType)type
{
TFShareBodyModel *t_model = [[TFShareBodyModel alloc] init];
[self getDetailsWithShareModel:t_model isShareApp:NO type:type production_id:production_id chapter_id:chapter_id];
[self showShareView:^(TFSharingPlatform platform) {
[self share:platform shareModel:t_model];
}];
}
+ (void)shareApp
{
TFShareBodyModel *t_model = [[TFShareBodyModel alloc] init];
[self getDetailsWithShareModel:t_model isShareApp:YES type:kNilOptions production_id:nil chapter_id:nil];
[self showShareView:^(TFSharingPlatform platform) {
[self share:platform shareModel:t_model];
}];
}
+ (void)shareWithTitle:(NSString *)title desc:(NSString *)desc imageUrl:(NSString *)imageUrl shareUrl:(NSString *)shareUrl
{
TFShareBodyModel *t_model = [[TFShareBodyModel alloc] init];
t_model.title = title;
t_model.desc = desc;
t_model.imageUrl = imageUrl;
t_model.shareUrl = shareUrl;
[self showShareView:^(TFSharingPlatform platform) {
[self share:platform shareModel:t_model];
}];
}
/// 从服务器获取分享的详细数据
+ (void)getDetailsWithShareModel:(TFShareBodyModel *)shareModel isShareApp:(BOOL)isShareApp type:(TFShareType)type production_id:(NSString * _Nullable)production_id chapter_id:(NSString * _Nullable)chapter_id
{
NSMutableDictionary *params = [NSMutableDictionary dictionary];
if (!isShareApp) {
[params setObject:@(type) forKey:@"type"];
[params setObject:production_id ?: @"" forKey:@"novel_id"];
if (!kObjectIsEmpty(chapter_id)) {
[params setObject:chapter_id forKey:@"chapter_id"];
}
}
[TFNetworkTools POST:isShareApp ? App_Share : App_Chapter_Share parameters:params model:TFShareModel.class success:^(BOOL isSuccess, TFShareModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
NSString *shareUrl = @"";
if (TFUserInfoManager.isLogin) {
shareUrl = [NSString stringWithFormat:@"%@?uid=%zd&osType=1&product=1", t_model.link ?: [NSString stringWithFormat:@"%@%@", APIURL, Site_Share], TFUserInfoManager.shareInstance.uid];
} else {
shareUrl = [NSString stringWithFormat:@"%@?osType=1&product=1", t_model.link ?: [NSString stringWithFormat:@"%@%@", APIURL, Site_Share]];
}
shareModel.title = @"";
shareModel.title = t_model.title;
shareModel.desc = t_model.desc;
shareModel.imageUrl = t_model.imgUrl;
shareModel.shareUrl = shareUrl;
} else {
shareModel.error = requestModel.msg ?: TFLocalizedString(@"分享错误");
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
shareModel.error = TFLocalizedString(@"分享错误");
}];
}
/// 弹出分享框
+ (void)showShareView:(void(^)(TFSharingPlatform platform))clickBlock
{
TFShareView *shareView = [[TFShareView alloc] init];
shareView.clickHandler = ^(TFSharingPlatform platform) {
!clickBlock ?: clickBlock(platform);
};
[shareView show];
}
/// 分享至指定平台
+ (void)share:(TFSharingPlatform)platform shareModel:(TFShareBodyModel *)shareModel
{
if (kObjectIsEmpty(shareModel.shareUrl) && kObjectIsEmpty(shareModel.imageUrl)) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"分享地址出错,请稍后重试")];
return;
}
// 获取分享平台的数据
NSMutableDictionary *params = ({
NSMutableDictionary *params = [NSMutableDictionary dictionary];
[params SSDKSetupShareParamsByText:shareModel.desc images:shareModel.shareImage url:[NSURL URLWithString:shareModel.shareUrl] title:shareModel.title type:SSDKContentTypeAuto];
params;
});
// 分享至指定平台
switch (platform) {
case TFSharingPlatformQQ: {
[ShareSDK share:SSDKPlatformSubTypeQQFriend parameters:params onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
if (error.code == 200104) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"请先安装客户端")];
return;
}
switch (state) {
case SSDKResponseStateSuccess: {
[self shareCallback];
}
break;
case SSDKResponseStateFail: {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"分享失败")];
}
break;
case SSDKResponseStateCancel:
break;
default: {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"分享失败")];
}
}
}];
}
break;
case TFSharingPlatformQQSpace: {
[ShareSDK share:SSDKPlatformSubTypeQZone parameters:params onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
if (error.code == 200104) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"请先安装客户端")];
return;
}
switch (state) {
case SSDKResponseStateSuccess: {
[self shareCallback];
}
break;
case SSDKResponseStateFail: {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"分享失败")];
}
break;
case SSDKResponseStateCancel:
break;
default: {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"分享失败")];
}
}
}];
}
break;
case TFSharingPlatformWeChat: {
[ShareSDK share:SSDKPlatformSubTypeWechatSession parameters:params onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
if (error.code == 200104) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"请先安装客户端")];
return;
}
switch (state) {
case SSDKResponseStateSuccess: {
[self shareCallback];
}
break;
case SSDKResponseStateFail: {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"分享失败")];
}
break;
case SSDKResponseStateCancel:
break;
default: {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"分享失败")];
}
}
}];
}
break;
case TFSharingPlatformFriendCircle: {
[ShareSDK share:SSDKPlatformSubTypeWechatTimeline parameters:params onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
if (error.code == 200104) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"请先安装客户端")];
return;
}
switch (state) {
case SSDKResponseStateSuccess: {
[self shareCallback];
}
break;
case SSDKResponseStateFail: {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"分享失败")];
}
break;
case SSDKResponseStateCancel:
break;
default: {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"分享失败")];
}
}
}];
}
default:
break;
}
}
/// 分享回调
+ (void)shareCallback
{
[TFNetworkTools POST:Share_Back parameters:nil model:nil success:^(BOOL isSuccess, NSDictionary *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Share_Success object:nil];
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"分享成功")];
}
} failure:nil];
}
@end
@@ -0,0 +1,22 @@
//
// TFShareModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/5.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFShareModel : NSObject
@property (nonatomic ,copy) NSString *link;
@property (nonatomic ,copy) NSString *title;
@property (nonatomic ,copy) NSString *desc;
@property (nonatomic ,copy) NSString *imgUrl;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,13 @@
//
// TFShareModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/5.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFShareModel.h"
@implementation TFShareModel
@end
@@ -0,0 +1,43 @@
//
// TFShareView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/5.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/*** 分享平台 ***/
typedef NS_ENUM(NSUInteger, TFSharingPlatform) {
TFSharingPlatformQQ = 0, /** 分享到 QQ */
TFSharingPlatformWeChat = 1, /** 分享到 微信 */
TFSharingPlatformQQSpace = 2, /** 分享到 QQ空间 */
TFSharingPlatformFriendCircle = 3, /** 分享到 朋友圈 */
};
/*** 分享类型 ***/
typedef NS_ENUM(NSUInteger, TFShareType) {
TFShareTypeBook = 1, /** 分享小说 */
TFShareTypeComic = 2, /** 分享漫画 */
TFShareTypeAudio = 3, /** 分享听书 */
};
typedef void(^ClickHandler)(TFSharingPlatform platform);
@interface TFShareView : UIView
@property (nonatomic ,copy) ClickHandler clickHandler;
/**
* 显示\隐藏
*/
- (void)show;
- (void)hidden;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,269 @@
//
// TFShareView.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/5.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFShareView.h"
#import "TFShareViewCell.h"
#import "UIView+BorderLine.h"
#import "UIView+LayoutCallback.h"
#define ZY_ItemCellHeight 100.f // 每个item的高度
@interface TFShareView () <UIGestureRecognizerDelegate, UICollectionViewDataSource, UICollectionViewDelegate>
{
UITapGestureRecognizer *tap;
}
@property (nonatomic ,strong) UIView *backView;
@property (nonatomic ,strong) UILabel *titleLabel;
@property (nonatomic ,strong) UICollectionView *mainCollectionView;
@property (nonatomic ,strong) UICollectionViewFlowLayout *mainCollectionViewFlowLayout;
@property (nonatomic ,strong) UIButton *cancelButton;
@property (nonatomic ,strong) NSMutableArray *dataSources;
@end
@implementation TFShareView
- (instancetype)init
{
if (self = [super init]) {
[self initialize];
[self createSubviews];
}
return self;
}
- (void)initialize
{
self.dataSources = [NSMutableArray array];
if (TF_WeChat_Share_Mode) {
[self.dataSources addObject:@[@"微信好友", @"login_wechat", [NSNumber numberWithInteger:TFSharingPlatformWeChat]]];
[self.dataSources addObject:@[@"朋友圈", @"share_wechat_timeline", [NSNumber numberWithInteger:TFSharingPlatformFriendCircle]]];
}
if (TF_QQ_Share_Mode) {
[self.dataSources addObject:@[@"QQ好友", @"login_qq", [NSNumber numberWithInteger:TFSharingPlatformQQ]]];
[self.dataSources addObject:@[@"QQ空间", @"share_qzone", [NSNumber numberWithInteger:TFSharingPlatformQQSpace]]];
}
self.userInteractionEnabled = YES;
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
self.backgroundColor = kBlackTransparentAlphaColor(0);
[kMainWindow addSubview:self];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidden)];
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[self addGestureRecognizer:tap];
self.mainCollectionView.scrollEnabled = YES;
if (self.dataSources.count <= 4) {
self.mainCollectionView.scrollEnabled = NO;
}
}
- (void)createSubviews
{
[self addSubview:self.backView];
WS(weakSelf)
self.titleLabel.frameBlock = ^(UIView * _Nonnull view) {
// 设置文字分割线
CALayer *splitLine = [CALayer layer];
splitLine.backgroundColor = kGrayLineColor.CGColor;
splitLine.anchorPoint = CGPointMake(0, 0);
splitLine.bounds = CGRectMake(0, 0, 160, 1);
splitLine.center = CGPointMake(weakSelf.titleLabel.centerX, weakSelf.titleLabel.centerY);
[weakSelf.backView.layer addSublayer:splitLine];
[weakSelf.backView bringSubviewToFront:view];
};
[self.backView addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kHalfMargin);
make.centerX.mas_equalTo(self.backView.mas_centerX);
make.width.mas_equalTo(80);
make.height.mas_equalTo(40);
}];
[self.backView addSubview:self.mainCollectionView];
[self.mainCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(self.titleLabel.mas_bottom).with.offset(kHalfMargin);
make.width.mas_equalTo(self.backView.mas_width);
make.height.mas_equalTo(ZY_ItemCellHeight);
}];
[self.backView addSubview:self.cancelButton];
[self.backView bringSubviewToFront:self.cancelButton];
[self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(self.mainCollectionView.mas_bottom);
make.width.mas_equalTo(self.backView.mas_width);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - kHalfMargin);
}];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.cancelButton addBorderLineWithBorderWidth:kCellLineHeight borderColor:kGrayLineColor cornerRadius:0 borderType:UIBorderSideTypeTop];
});
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.dataSources.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TFShareViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TFShareViewCell" forIndexPath:indexPath];
cell.sourceArray = [self.dataSources objectOrNilAtIndex:indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *t_arr = [self.dataSources objectOrNilAtIndex:indexPath.row];
TFSharingPlatform platform = (TFSharingPlatform)[[t_arr objectOrNilAtIndex:2] integerValue];
!self.clickHandler ?: self.clickHandler(platform);
[self hidden];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (self.dataSources.count <= 4) {
return CGSizeMake((SCREEN_WIDTH - 2 * kHalfMargin) / self.dataSources.count, ZY_ItemCellHeight);
}
return CGSizeMake(SCREEN_WIDTH / 4.7, ZY_ItemCellHeight);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
if (self.dataSources.count <= 4) {
return UIEdgeInsetsMake(0, kHalfMargin, 0, kHalfMargin);
}
return UIEdgeInsetsMake(0, 0, 0, 0);
}
- (void)show
{
if (self.dataSources.count == 0) {
return;
}
WS(weakSelf)
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
weakSelf.backgroundColor = kBlackTransparentAlphaColor(0.5);
weakSelf.backView.frame = CGRectMake(0, SCREEN_HEIGHT - (kHalfMargin + 40 + kHalfMargin + ZY_ItemCellHeight + PUB_TABBAR_HEIGHT - kHalfMargin), SCREEN_WIDTH, kHalfMargin + 40 + kHalfMargin + ZY_ItemCellHeight + PUB_TABBAR_HEIGHT - kHalfMargin);
}];
}
- (void)hidden
{
WS(weakSelf)
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
weakSelf.backgroundColor = kBlackTransparentAlphaColor(0);
weakSelf.backView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 40 + ZY_ItemCellHeight + PUB_TABBAR_HEIGHT);
} completion:^(BOOL finished) {
[weakSelf removeFromKeyWindow];
}];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([touch.view isEqual:self]) {
return YES;
} else {
return NO;
}
}
- (void)removeFromKeyWindow
{
if (self.superview) {
[self removeFromSuperview];
}
}
- (UIView *)backView
{
if (!_backView) {
_backView = [[UIView alloc] init];
_backView.userInteractionEnabled = YES;
_backView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, kHalfMargin + 40 + kHalfMargin + ZY_ItemCellHeight + PUB_TABBAR_HEIGHT - kHalfMargin);
_backView.backgroundColor = [UIColor whiteColor];
[_backView addRoundingCornersWithRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight];
_backView.clipsToBounds = YES;
}
return _backView;
}
- (UILabel *)titleLabel
{
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.backgroundColor = [UIColor whiteColor];
_titleLabel.textColor = kGrayTextColor;
_titleLabel.text = TFLocalizedString(@"分享至");
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.font = kMainFont;
}
return _titleLabel;
}
- (UIButton *)cancelButton
{
if (!_cancelButton) {
_cancelButton = [[UIButton alloc] init];
_cancelButton.backgroundColor = [UIColor whiteColor];
[_cancelButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET / 2, 0)];
[_cancelButton setTitle:TFLocalizedString(@"取消") forState:UIControlStateNormal];
[_cancelButton setTitleColor:kGrayTextColor forState:UIControlStateNormal];
[_cancelButton.titleLabel setFont:kMainFont];
[_cancelButton addTarget:self action:@selector(hidden) forControlEvents:UIControlEventTouchUpInside];
}
return _cancelButton;
}
- (UICollectionView *)mainCollectionView
{
if (!_mainCollectionView) {
_mainCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.mainCollectionViewFlowLayout];
_mainCollectionView.userInteractionEnabled = YES;
_mainCollectionView.backgroundColor = [UIColor clearColor];
_mainCollectionView.showsVerticalScrollIndicator = NO;
_mainCollectionView.showsHorizontalScrollIndicator = NO;
_mainCollectionView.alwaysBounceHorizontal = YES;
_mainCollectionView.delegate = self;
_mainCollectionView.dataSource = self;
if (@available(iOS 11.0, *)) {
_mainCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[_mainCollectionView registerClass:[TFShareViewCell class] forCellWithReuseIdentifier:@"TFShareViewCell"];
}
return _mainCollectionView;
}
- (UICollectionViewFlowLayout *)mainCollectionViewFlowLayout
{
if (!_mainCollectionViewFlowLayout) {
_mainCollectionViewFlowLayout = [[UICollectionViewFlowLayout alloc] init];
_mainCollectionViewFlowLayout.minimumInteritemSpacing = 0;
_mainCollectionViewFlowLayout.minimumLineSpacing = 0;
_mainCollectionViewFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
}
return _mainCollectionViewFlowLayout;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
@@ -0,0 +1,19 @@
//
// TFShareViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/5.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFShareViewCell : UICollectionViewCell
@property (nonatomic ,strong) NSArray *sourceArray;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,78 @@
//
// TFShareViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/5.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFShareViewCell.h"
@interface TFShareViewCell ()
@property (nonatomic ,strong) UIImageView *iconView;
@property (nonatomic ,strong) UILabel *titleView;
@end
@implementation TFShareViewCell
- (UIImageView *)iconView
{
if (!_iconView) {
_iconView = [[UIImageView alloc] init];
_iconView.userInteractionEnabled = YES;
}
return _iconView;
}
- (UILabel *)titleView
{
if (!_titleView) {
_titleView = [[UILabel alloc] init];
_titleView.backgroundColor = [UIColor whiteColor];
_titleView.textColor = kGrayTextColor;
_titleView.font = kFont12;
_titleView.textAlignment = NSTextAlignmentCenter;
_titleView.userInteractionEnabled = NO;
}
return _titleView;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.userInteractionEnabled = YES;
self.backgroundColor = [UIColor whiteColor];
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
[self addSubview:self.iconView];
[self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(60);
make.centerX.mas_equalTo(self.mas_centerX);
make.top.mas_equalTo(5);
}];
[self addSubview:self.titleView];
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(self.iconView.mas_bottom);
make.width.mas_equalTo(self.mas_width);
make.height.mas_equalTo(30);
}];
}
- (void)setSourceArray:(NSArray *)sourceArray
{
_sourceArray = sourceArray;
self.iconView.image = [UIImage imageNamed:[sourceArray objectOrNilAtIndex:1]];
self.titleView.text = [sourceArray objectOrNilAtIndex:0];
}
@end