小说绘上架版本
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// TFAgreementAlertView.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TFAlertView.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TFAgreementAlertView : TFAlertView
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,159 @@
|
||||
//
|
||||
// TFAgreementAlertView.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFAgreementAlertView.h"
|
||||
#import "TFWebViewController.h"
|
||||
#import "AppDelegate.h"
|
||||
#import <MOBFoundation/MobSDK+Privacy.h>
|
||||
|
||||
@implementation TFAgreementAlertView
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
/*** 穿山甲的背景视图,解决穿山甲加载广告期间的空白页面 ***/
|
||||
UIView *backgroundView = ({
|
||||
NSString *lauchStoryboardName = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchStoryboardName"];
|
||||
switch (TFLanguageManager.localizedLanguage) {
|
||||
case TFLanguageTypeSimplifiedChinese:
|
||||
lauchStoryboardName = @"LaunchScreen_ZH";
|
||||
break;
|
||||
case TFLanguageTypeTraditionalChinese:
|
||||
lauchStoryboardName = @"LaunchScreen_ZW";
|
||||
break;
|
||||
case TFLanguageTypeEnglish:
|
||||
lauchStoryboardName = @"LaunchScreen_EN";
|
||||
break;
|
||||
case TFLanguageTypeTail:
|
||||
lauchStoryboardName = @"LaunchScreen_TH";
|
||||
break;
|
||||
default:
|
||||
lauchStoryboardName = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchStoryboardName"];
|
||||
break;
|
||||
}
|
||||
UIViewController *launchScreen = [[UIStoryboard storyboardWithName:lauchStoryboardName bundle:nil] instantiateInitialViewController];
|
||||
UIView *backgroundView = launchScreen.view;
|
||||
backgroundView.backgroundColor = [UIColor whiteColor];
|
||||
backgroundView.frame = [UIScreen mainScreen].bounds;
|
||||
backgroundView;
|
||||
});
|
||||
[self addSubview:backgroundView];
|
||||
[self sendSubviewToBack:backgroundView];
|
||||
|
||||
UIView *shadowView = [[UIView alloc] init];
|
||||
shadowView.backgroundColor = kColorRGBA(0, 0, 0, 0.3);
|
||||
[backgroundView addSubview:shadowView];
|
||||
[shadowView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(backgroundView);
|
||||
}];
|
||||
|
||||
|
||||
self.alertDisappearType = TFAlertViewDisappearTypeConfirm;
|
||||
self.closeButton.hidden = YES;
|
||||
self.alertTitle = TFLocalizedString(@"用户隐私保护提示");
|
||||
|
||||
NSString *prefix = [NSString stringWithFormat:@"%@%@", App_Name, TFLocalizedString(@"隐私政策")];
|
||||
NSString *suffix = TFLocalizedString(@"软件许可及服务协议");
|
||||
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:TFLocalizedString(@"为了更好的保护您的隐私和信息安全,根据国家相关法律规定和国家标准制定并执行《%@》及《%@》,请您在使用前务必仔细阅读并透彻理解,如果您继续使用本产品即代表您同意本平台的协议条款,我们会全力保护您的个人信息安全。"), prefix, suffix]];
|
||||
|
||||
NSRange range1 = [str.string rangeOfString:prefix];
|
||||
NSRange range2 = [str.string rangeOfString:suffix];
|
||||
|
||||
[str setColor:kColorRGB(102, 102, 102)];
|
||||
[str setFont:kMainFont];
|
||||
[str setLineSpacing:4];
|
||||
|
||||
[str setTextHighlightRange:range1 color:kMainColor backgroundColor:[UIColor whiteColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
|
||||
if (![TFViewHelper getWindowRootController].presentedViewController) {
|
||||
TFWebViewController *web = [[TFWebViewController alloc] init];
|
||||
web.navTitle = TFLocalizedString(@"隐私政策");
|
||||
AppDelegate *delegate = (AppDelegate *)kRCodeSync([UIApplication sharedApplication].delegate);
|
||||
web.URLString = delegate.checkSettingModel.protocol_list.privacy ?: [NSString stringWithFormat:@"%@%@?language=%@", APIURL, Privacy_Policy, TFLanguageManager.serverLocalized];
|
||||
|
||||
web.isPresentState = YES;
|
||||
[[TFViewHelper getWindowRootController] presentViewController:web animated:YES completion:nil];
|
||||
}
|
||||
}];
|
||||
|
||||
[str setTextHighlightRange:range2 color:kMainColor backgroundColor:[UIColor whiteColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
|
||||
if (![TFViewHelper getWindowRootController].presentedViewController) {
|
||||
TFWebViewController *web = [[TFWebViewController alloc] init];
|
||||
web.navTitle = TFLocalizedString(@"软件许可");
|
||||
web.URLString = [NSString stringWithFormat:@"%@%@?language=%@", APIURL, Notify_Note, TFLanguageManager.serverLocalized];
|
||||
web.isPresentState = YES;
|
||||
[[TFViewHelper getWindowRootController] presentViewController:web animated:YES completion:nil];
|
||||
}
|
||||
}];
|
||||
self.attributedStr = str;
|
||||
self.contentScrollView.hidden = YES;
|
||||
|
||||
UIScrollView *mainScrollView = [[UIScrollView alloc] init];
|
||||
mainScrollView.showsHorizontalScrollIndicator = NO;
|
||||
[self addSubview:mainScrollView];
|
||||
|
||||
[mainScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
|
||||
make.top.equalTo(self.contentScrollView).offset(kMargin);
|
||||
make.left.right.bottom.equalTo(self.contentScrollView);
|
||||
}];
|
||||
|
||||
YYLabel *detailView = [[YYLabel alloc] init];
|
||||
detailView.backgroundColor = [UIColor whiteColor];
|
||||
detailView.numberOfLines = 0;
|
||||
detailView.preferredMaxLayoutWidth = SCREEN_WIDTH - 3 * kMargin - 2 * kMargin;
|
||||
detailView.attributedText = str;
|
||||
[mainScrollView addSubview:detailView];
|
||||
|
||||
[detailView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.width.equalTo(mainScrollView);
|
||||
}];
|
||||
|
||||
self.cancelTitle = TFLocalizedString(@"拒绝并退出");
|
||||
self.confirmTitle = TFLocalizedString(@"我已经阅读并同意");
|
||||
|
||||
[self.cancelButton addTarget:self action:@selector(cancelButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.confirmButton addTarget:self action:@selector(confirmButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
|
||||
- (void)showAlertView
|
||||
{
|
||||
[super showAlertView];
|
||||
}
|
||||
|
||||
- (void)willMoveToWindow:(nullable UIWindow *)newWindow
|
||||
{
|
||||
[super willMoveToWindow:newWindow];
|
||||
if (!newWindow) { // 跳转到协议时newWindow会为空
|
||||
[UIApplication sharedApplication].statusBarHidden = NO;
|
||||
} else {
|
||||
[UIApplication sharedApplication].statusBarHidden = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cancelButtonClick
|
||||
{
|
||||
UIWindow *window = [UIApplication sharedApplication].keyWindow;
|
||||
[UIView animateWithDuration:kAnimatedDuration animations:^{
|
||||
window.alpha = 0;
|
||||
window.frame = CGRectMake(0, window.bounds.size.height / 2, window.bounds.size.width, 0.5);
|
||||
} completion:^(BOOL finished) {
|
||||
exit(0);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)confirmButtonClick
|
||||
{
|
||||
[self closeAlertView];
|
||||
|
||||
TFSystemInfoManager.isAgree = YES;
|
||||
!self.confirmButtonClickBlock ?: self.confirmButtonClickBlock();
|
||||
[MobSDK uploadPrivacyPermissionStatus:YES onResult:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// TFAlertView.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// 按钮样式
|
||||
typedef NS_ENUM(NSUInteger, TFAlertButtonType) {
|
||||
TFAlertButtonTypeNone, // 底部无按钮
|
||||
TFAlertButtonTypeSingleCancel, // 底部单一取消按钮
|
||||
TFAlertButtonTypeSingleConfirm, // 底部单一确认按钮
|
||||
TFAlertButtonTypeDouble // 底部双按钮
|
||||
};
|
||||
|
||||
// 弹框消失状态
|
||||
typedef NS_ENUM(NSUInteger, TFAlertViewDisappearType) {
|
||||
TFAlertViewDisappearTypeNormal, // 点击按钮或弹框以外位置消失
|
||||
TFAlertViewDisappearTypeConfirm, // 只能点击按钮消失
|
||||
TFAlertViewDisappearTypeNever // 不可消失
|
||||
};
|
||||
|
||||
@class TFAlertView;
|
||||
typedef void(^ClickButtonBlock)(TFAlertView *view);
|
||||
|
||||
@interface TFAlertView : UIView
|
||||
|
||||
@property (nonatomic ,copy) void(^confirmButtonClickBlock)(void);
|
||||
@property (nonatomic ,copy) void(^cancelButtonClickBlock)(void);
|
||||
// 按钮样式
|
||||
@property (nonatomic ,assign) TFAlertButtonType alertBtnType;
|
||||
// 弹框消失状态
|
||||
@property (nonatomic ,assign) TFAlertViewDisappearType alertDisappearType;
|
||||
// 是否显示按钮分割线
|
||||
@property (nonatomic ,assign) BOOL showDivider;
|
||||
|
||||
@property (nonatomic ,copy) NSString *alertTitle;
|
||||
@property (nonatomic ,copy) NSString *alertDetailContent;
|
||||
@property (nonatomic ,strong) NSMutableAttributedString *attributedStr;
|
||||
@property (nonatomic ,copy) NSString *cancelTitle;
|
||||
@property (nonatomic ,copy) NSString *confirmTitle;
|
||||
|
||||
- (void)showAlertView;
|
||||
|
||||
- (void)closeAlertView;
|
||||
|
||||
- (instancetype)initInController;
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame UNAVAILABLE_ATTRIBUTE;
|
||||
|
||||
/*** 子类使用变量 ***/
|
||||
@property (nonatomic ,assign ,readonly) CGFloat alertViewWidth;
|
||||
@property (nonatomic ,assign ,readonly) CGFloat alertViewBtnHeight;
|
||||
@property (nonatomic ,strong) UIView *alertBackView;
|
||||
@property (nonatomic ,strong) UIButton *closeButton;
|
||||
@property (nonatomic ,strong) UIButton *confirmButton;
|
||||
@property (nonatomic ,strong) UIButton *cancelButton;
|
||||
@property (nonatomic ,strong) UILabel *alertTitleLabel;
|
||||
@property (nonatomic ,strong) YYLabel *contentLabel;
|
||||
@property (nonatomic ,strong) UIScrollView *contentScrollView;
|
||||
|
||||
- (void)createSubviews;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,394 @@
|
||||
//
|
||||
// TFAlertView.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFAlertView.h"
|
||||
|
||||
@interface TFAlertView ()<UIGestureRecognizerDelegate>
|
||||
|
||||
@property (nonatomic ,strong) UITapGestureRecognizer *dismissTapGesture;
|
||||
@property (nonatomic ,assign) CGFloat alertViewBtnWidth;
|
||||
@property (nonatomic ,assign) BOOL inController;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFAlertView
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
|
||||
_inController = NO;
|
||||
[self initialize];
|
||||
[self createSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initInController
|
||||
{
|
||||
if (self = [super init]) {
|
||||
|
||||
_inController = YES;
|
||||
[self initialize];
|
||||
[self createSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initialize
|
||||
{
|
||||
_showDivider = YES;
|
||||
_alertViewBtnHeight = 50.0f;
|
||||
_alertViewWidth = SCREEN_WIDTH - 3 * kMargin;
|
||||
self.alertBtnType = TFAlertButtonTypeDouble;
|
||||
self.alertDisappearType = TFAlertViewDisappearTypeNormal;
|
||||
|
||||
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
self.backgroundColor = kBlackTransparentColor;
|
||||
if (_inController) {
|
||||
[kMainWindow.rootViewController.view addSubview:self];
|
||||
} else {
|
||||
[kMainWindow addSubview:self];
|
||||
}
|
||||
if (!self.superview) {
|
||||
UIViewController *vc = [UIApplication sharedApplication].windows.firstObject.rootViewController;
|
||||
[vc.view addSubview:self];
|
||||
}
|
||||
|
||||
self.dismissTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeAlertView)];
|
||||
self.dismissTapGesture.numberOfTapsRequired = 1;
|
||||
self.dismissTapGesture.delegate = self;
|
||||
[self addGestureRecognizer:self.dismissTapGesture];
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
// 添加背景
|
||||
[self addSubview:self.alertBackView];
|
||||
// 添加关闭按钮
|
||||
[self.alertBackView addSubview:self.closeButton];
|
||||
// 添加标题
|
||||
[self.alertBackView addSubview:self.alertTitleLabel];
|
||||
// 添加内容
|
||||
[self.alertBackView addSubview:self.contentScrollView];
|
||||
|
||||
[self.contentScrollView addSubview:self.contentLabel];
|
||||
// 取消按钮
|
||||
[self.alertBackView addSubview:self.cancelButton];
|
||||
// 确认按钮
|
||||
[self.alertBackView addSubview:self.confirmButton];
|
||||
}
|
||||
|
||||
// 显示弹框
|
||||
- (void)showAlertView
|
||||
{
|
||||
[self.alertBackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(self.alertViewWidth);
|
||||
make.bottom.mas_equalTo(self.confirmButton.mas_bottom).with.offset(0);
|
||||
make.centerX.mas_equalTo(self.mas_centerX);
|
||||
make.centerY.mas_equalTo(self.mas_centerY).with.offset(0);
|
||||
}];
|
||||
|
||||
[self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.alertBackView.mas_top);
|
||||
make.right.mas_equalTo(self.alertBackView.mas_right);
|
||||
make.width.height.mas_equalTo(50);
|
||||
}];
|
||||
|
||||
[self.alertTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.alertBackView.mas_left).with.offset(kMargin);
|
||||
make.right.mas_equalTo(self.alertBackView.mas_right).with.offset(- kMargin);
|
||||
make.top.mas_equalTo(self.alertBackView.mas_top).with.offset(kMargin);
|
||||
if (self.alertTitle.length > 0) {
|
||||
make.height.mas_equalTo(30);
|
||||
} else {
|
||||
make.height.mas_equalTo(CGFLOAT_MIN);
|
||||
}
|
||||
}];
|
||||
|
||||
[self.contentScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self.alertTitleLabel.centerX);
|
||||
make.top.mas_equalTo(self.alertTitleLabel.mas_bottom);
|
||||
make.width.mas_equalTo(self.alertViewWidth - 2 * kMargin);
|
||||
make.height.mas_equalTo([self getContentScrollViewHeight]);
|
||||
}];
|
||||
|
||||
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.top.mas_equalTo(0);
|
||||
make.width.mas_equalTo(self.contentScrollView.mas_width);
|
||||
make.height.mas_equalTo([self getContentLabelHeight]);
|
||||
}];
|
||||
|
||||
|
||||
[self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.alertBackView.mas_left).with.offset(0);
|
||||
make.top.mas_equalTo(self.contentScrollView.mas_bottom).with.offset(kMargin);
|
||||
make.height.mas_equalTo(_alertViewBtnHeight);
|
||||
if (self.alertBtnType == TFAlertButtonTypeSingleConfirm) {
|
||||
make.width.mas_equalTo(CGFLOAT_MIN);
|
||||
} else {
|
||||
make.width.mas_equalTo(self.alertViewBtnWidth);
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
[self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.alertBackView.mas_right).with.offset(0);
|
||||
make.top.mas_equalTo(self.contentScrollView.mas_bottom).with.offset(kMargin);
|
||||
make.height.mas_equalTo(_alertViewBtnHeight);
|
||||
if (self.alertBtnType == TFAlertButtonTypeSingleCancel) {
|
||||
make.width.mas_equalTo(CGFLOAT_MIN);
|
||||
} else {
|
||||
make.width.mas_equalTo(self.alertViewBtnWidth);
|
||||
}
|
||||
}];
|
||||
|
||||
if (self.alertBtnType != TFAlertButtonTypeNone && self.showDivider) {
|
||||
UIView *line = [[UIView alloc] init];
|
||||
line.backgroundColor = kGrayLineColor;
|
||||
[self.alertBackView addSubview:line];
|
||||
|
||||
[line mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.alertBackView.mas_left);
|
||||
make.right.mas_equalTo(self.alertBackView.mas_right);
|
||||
make.height.mas_equalTo(kCellLineHeight + 0.1f);
|
||||
make.bottom.mas_equalTo(self.alertBackView.mas_bottom).with.offset(- _alertViewBtnHeight);
|
||||
}];
|
||||
|
||||
if (self.alertBtnType == TFAlertButtonTypeDouble) {
|
||||
UIView *line = [[UIView alloc] init];
|
||||
line.backgroundColor = kGrayLineColor;
|
||||
[self.alertBackView addSubview:line];
|
||||
|
||||
[line mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.confirmButton.mas_left);
|
||||
make.top.mas_equalTo(self.confirmButton.mas_top);
|
||||
make.height.mas_equalTo(self.confirmButton.mas_height);
|
||||
make.width.mas_equalTo(kCellLineHeight + 0.1f);
|
||||
}];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭弹框
|
||||
- (void)closeAlertView
|
||||
{
|
||||
[self removeFromSuperview];
|
||||
}
|
||||
|
||||
- (CGFloat)getContentLabelHeight
|
||||
{
|
||||
if (self.attributedStr.length > 0) {
|
||||
return [TFViewHelper getDynamicHeightWithLabelFont:kMainFont labelWidth:SCREEN_WIDTH - 3 * kMargin labelText:self.attributedStr.string] + 2 * kMargin;
|
||||
} else if (self.alertDetailContent.length > 0) {
|
||||
return [TFViewHelper getDynamicHeightWithLabelFont:kMainFont labelWidth:SCREEN_WIDTH - 3 * kMargin labelText:self.alertDetailContent] + kMargin;
|
||||
}
|
||||
return CGFLOAT_MIN;
|
||||
}
|
||||
|
||||
- (CGFloat)getContentScrollViewHeight
|
||||
{
|
||||
if ([self getContentLabelHeight] > (SCREEN_HEIGHT / 3)) {
|
||||
[self.contentScrollView setContentSize:CGSizeMake(0, [self getContentLabelHeight])];
|
||||
return SCREEN_HEIGHT / 3;
|
||||
}
|
||||
return [self getContentLabelHeight];
|
||||
}
|
||||
|
||||
//- (NSString *)alertTitle
|
||||
//{
|
||||
// if (!_alertTitle) {
|
||||
// return TFLocalizedString(@"提示");
|
||||
// }
|
||||
// return _alertTitle;
|
||||
//}
|
||||
|
||||
- (void)setAlertTitle:(NSString *)alertTitle
|
||||
{
|
||||
_alertTitle = alertTitle;
|
||||
|
||||
self.alertTitleLabel.text = alertTitle;
|
||||
}
|
||||
|
||||
- (void)setAlertDetailContent:(NSString *)alertDetailContent
|
||||
{
|
||||
_alertDetailContent = alertDetailContent;
|
||||
|
||||
self.contentLabel.text = alertDetailContent;
|
||||
}
|
||||
|
||||
- (void)setAttributedStr:(NSMutableAttributedString *)attributedStr
|
||||
{
|
||||
_attributedStr = attributedStr;
|
||||
|
||||
self.contentLabel.attributedText = attributedStr;
|
||||
}
|
||||
|
||||
- (void)setCancelTitle:(NSString *)cancelTitle
|
||||
{
|
||||
[self.cancelButton setTitle:cancelTitle forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (void)setConfirmTitle:(NSString *)confirmTitle
|
||||
{
|
||||
[self.confirmButton setTitle:confirmTitle forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (void)setAlertBtnType:(TFAlertButtonType)alertBtnType
|
||||
{
|
||||
_alertBtnType = alertBtnType;
|
||||
|
||||
switch (alertBtnType) {
|
||||
case TFAlertButtonTypeNone:
|
||||
self.alertViewBtnWidth = CGFLOAT_MIN;
|
||||
_alertViewBtnHeight = CGFLOAT_MIN;
|
||||
break;
|
||||
case TFAlertButtonTypeSingleConfirm:
|
||||
case TFAlertButtonTypeSingleCancel:
|
||||
self.alertViewBtnWidth = self.alertViewWidth;
|
||||
_alertViewBtnHeight = 44.0f;
|
||||
break;
|
||||
case TFAlertButtonTypeDouble:
|
||||
self.alertViewBtnWidth = (self.alertViewWidth) / 2;
|
||||
_alertViewBtnHeight = 44.0f;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setAlertDisappearType:(TFAlertViewDisappearType)alertDisappearType
|
||||
{
|
||||
_alertDisappearType = alertDisappearType;
|
||||
|
||||
if (alertDisappearType != TFAlertViewDisappearTypeNormal) {
|
||||
[self removeGestureRecognizer:self.dismissTapGesture];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - lazy
|
||||
- (UIView *)alertBackView
|
||||
{
|
||||
if (!_alertBackView) {
|
||||
_alertBackView = [[UIView alloc] init];
|
||||
_alertBackView.backgroundColor = [UIColor whiteColor];
|
||||
_alertBackView.layer.cornerRadius = 8;
|
||||
[self addSubview:_alertBackView];
|
||||
}
|
||||
return _alertBackView;
|
||||
}
|
||||
|
||||
- (UIButton *)closeButton
|
||||
{
|
||||
if (!_closeButton) {
|
||||
_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
_closeButton.tintColor = kGrayTextLightColor;
|
||||
[_closeButton setImageEdgeInsets:UIEdgeInsetsMake(15, 15, 15, 15)];
|
||||
[_closeButton setImage:[[UIImage imageNamed:@"public_close"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
||||
[_closeButton addTarget:self action:@selector(closeAlertView) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _closeButton;
|
||||
}
|
||||
|
||||
- (UILabel *)alertTitleLabel
|
||||
{
|
||||
if (!_alertTitleLabel) {
|
||||
_alertTitleLabel = [[UILabel alloc] init];
|
||||
_alertTitleLabel.text = self.alertTitle;
|
||||
_alertTitleLabel.backgroundColor = [UIColor clearColor];
|
||||
_alertTitleLabel.font = kBoldFont16;
|
||||
_alertTitleLabel.textColor = kBlackColor;
|
||||
_alertTitleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_alertTitleLabel.numberOfLines = 1;
|
||||
}
|
||||
return _alertTitleLabel;
|
||||
}
|
||||
|
||||
- (UIScrollView *)contentScrollView
|
||||
{
|
||||
if (!_contentScrollView) {
|
||||
_contentScrollView = [[UIScrollView alloc] init];
|
||||
_contentScrollView.showsVerticalScrollIndicator = NO;
|
||||
_contentScrollView.showsHorizontalScrollIndicator = NO;
|
||||
}
|
||||
return _contentScrollView;
|
||||
}
|
||||
|
||||
- (YYLabel *)contentLabel
|
||||
{
|
||||
if (!_contentLabel) {
|
||||
_contentLabel = [[YYLabel alloc] init];
|
||||
_contentLabel.numberOfLines = 0;
|
||||
_contentLabel.font = kMainFont;
|
||||
_contentLabel.textColor = kGrayTextLightColor;
|
||||
_contentLabel.textAlignment = NSTextAlignmentCenter;
|
||||
}
|
||||
return _contentLabel;
|
||||
}
|
||||
|
||||
- (UIButton *)confirmButton
|
||||
{
|
||||
if (!_confirmButton) {
|
||||
_confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
_confirmButton.backgroundColor = kWhiteColor;
|
||||
_confirmButton.layer.cornerRadius = 8;
|
||||
[_confirmButton.titleLabel setFont:kMainFont];
|
||||
[_confirmButton setTitle:TFLocalizedString(@"确定") forState:UIControlStateNormal];
|
||||
[_confirmButton setTitleColor:kMainColor forState:UIControlStateNormal];
|
||||
[_confirmButton addTarget:self action:@selector(confirmButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _confirmButton;
|
||||
}
|
||||
|
||||
- (UIButton *)cancelButton
|
||||
{
|
||||
if (!_cancelButton) {
|
||||
_cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
_cancelButton.backgroundColor = kWhiteColor;
|
||||
_cancelButton.layer.cornerRadius = 8;
|
||||
[_cancelButton.titleLabel setFont:kMainFont];
|
||||
[_cancelButton setTitle:TFLocalizedString(@"取消") forState:UIControlStateNormal];
|
||||
[_cancelButton setTitleColor:kBlackColor forState:UIControlStateNormal];
|
||||
[_cancelButton addTarget:self action:@selector(cancelButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _cancelButton;
|
||||
}
|
||||
|
||||
#pragma mark - action
|
||||
- (void)cancelButtonClick
|
||||
{
|
||||
if (self.cancelButtonClickBlock) {
|
||||
self.cancelButtonClickBlock();
|
||||
}
|
||||
[self closeAlertView];
|
||||
}
|
||||
|
||||
- (void)confirmButtonClick
|
||||
{
|
||||
if (self.confirmButtonClickBlock) {
|
||||
self.confirmButtonClickBlock();
|
||||
}
|
||||
|
||||
if (self.alertDisappearType == TFAlertViewDisappearTypeNever) {
|
||||
return;
|
||||
}
|
||||
|
||||
[self closeAlertView];
|
||||
}
|
||||
|
||||
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
|
||||
{
|
||||
if ([touch.view isEqual:self.confirmButton] || [touch.view isEqual:self]) {
|
||||
return YES;
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// TFEvaluationAlertView.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TFAlertView.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TFEvaluationAlertView : TFAlertView
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,102 @@
|
||||
//
|
||||
// TFEvaluationAlertView.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFEvaluationAlertView.h"
|
||||
|
||||
@interface TFEvaluationAlertView ()
|
||||
|
||||
@property (nonatomic ,strong) UIImageView *topImageView;
|
||||
@property (nonatomic ,strong) UIButton *rejectBtn;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFEvaluationAlertView
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
[self addSubview:self.alertBackView];
|
||||
|
||||
self.showDivider = NO;
|
||||
|
||||
self.alertTitleLabel.font = kFont30;
|
||||
self.alertTitleLabel.text = TFLocalizedString(@"应用好评");
|
||||
self.alertDetailContent = TFLocalizedString(@"使用还满意么?满意请点个赞呗");
|
||||
self.cancelTitle = TFLocalizedString(@"我要吐槽");
|
||||
|
||||
self.cancelButton.layer.borderColor = kColorRGBA(62, 120, 232, 1).CGColor;
|
||||
self.cancelButton.layer.borderWidth = 0.5;
|
||||
self.cancelButton.layer.cornerRadius = self.alertViewBtnHeight / 2;
|
||||
self.cancelButton.backgroundColor = [UIColor whiteColor];
|
||||
[self.cancelButton setTitleColor:kColorRGBA(62, 120, 232, 1) forState:UIControlStateNormal];
|
||||
|
||||
self.confirmTitle = TFLocalizedString(@"五星好评");
|
||||
self.confirmButton.layer.cornerRadius = self.alertViewBtnHeight / 2;
|
||||
self.confirmButton.backgroundColor = kColorRGBA(62, 120, 232, 1);
|
||||
[self.confirmButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
|
||||
|
||||
self.rejectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[self.rejectBtn setTitle:TFLocalizedString(@"残忍拒绝") forState:UIControlStateNormal];
|
||||
[self.rejectBtn setTitleColor:kGrayTextLightColor forState:UIControlStateNormal];
|
||||
[self.rejectBtn.titleLabel setFont:kMainFont];
|
||||
[self.rejectBtn addTarget:self action:@selector(closeAlertView) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.alertBackView addSubview:self.rejectBtn];
|
||||
}
|
||||
|
||||
- (void)showAlertView
|
||||
{
|
||||
[super showAlertView];
|
||||
|
||||
self.topImageView = [[UIImageView alloc] init];
|
||||
self.topImageView.image = [UIImage imageNamed:@"public_evaluation.png"];
|
||||
self.topImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
[self.alertBackView addSubview:self.topImageView];
|
||||
|
||||
[self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(self.alertBackView.mas_width).with.multipliedBy(0.8);
|
||||
make.height.mas_equalTo(self.alertBackView.mas_width).with.multipliedBy(0.5);
|
||||
make.centerX.mas_equalTo(self.alertBackView.mas_centerX);
|
||||
make.bottom.mas_equalTo(self.alertBackView.mas_top).with.offset(2 * kMargin);
|
||||
}];
|
||||
|
||||
[self.alertTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.alertBackView.mas_top).with.offset(3 * kMargin);
|
||||
make.height.mas_equalTo(self.alertTitleLabel.intrinsicContentSize.height);
|
||||
}];
|
||||
|
||||
[self.confirmButton mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.contentScrollView.mas_bottom).with.offset(kMargin);
|
||||
make.centerX.mas_equalTo(self.alertTitleLabel.mas_centerX);
|
||||
make.width.mas_equalTo(self.alertBackView.mas_width).multipliedBy(0.5);
|
||||
make.height.mas_equalTo(self.alertViewBtnHeight);
|
||||
}];
|
||||
|
||||
[self.cancelButton mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self.confirmButton.mas_centerX);
|
||||
make.top.mas_equalTo(self.confirmButton.mas_bottom).with.offset(kHalfMargin);
|
||||
make.width.mas_equalTo(self.confirmButton.mas_width);
|
||||
make.height.mas_equalTo(self.confirmButton.mas_height);
|
||||
}];
|
||||
|
||||
[self.rejectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self.confirmButton.mas_centerX);
|
||||
make.top.mas_equalTo(self.cancelButton.mas_bottom).with.offset(5);
|
||||
make.width.mas_equalTo(self.confirmButton.mas_width);
|
||||
make.height.mas_equalTo(self.confirmButton.mas_height);
|
||||
}];
|
||||
|
||||
[self.alertBackView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(self.alertViewWidth);
|
||||
make.bottom.mas_equalTo(self.rejectBtn.mas_bottom).with.offset(kHalfMargin);
|
||||
make.centerX.mas_equalTo(self.mas_centerX);
|
||||
make.centerY.mas_equalTo(self.mas_centerY);
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// TFGiftAlertView.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@class WXYZ_TickectAlertModel, WXYZ_GiftMonthlyPassListModel;
|
||||
|
||||
@interface TFGiftAlertView : TFAlertView
|
||||
|
||||
- (void)setAlertModel:(WXYZ_TickectAlertModel *)alertModel giftModel:(WXYZ_GiftMonthlyPassListModel *)giftModel production_id:(NSInteger)production_id ticketBlock:(void(^)(NSInteger number))ticketBlock;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// TFGiftAlertView.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFGiftAlertView.h"
|
||||
#import "WXYZ_TickectAlertModel.h"
|
||||
#import "WXYZ_GiftMonthlyPassModel.h"
|
||||
#import "TFReaderBookManager.h"
|
||||
#import "TFRechargeViewController.h"
|
||||
|
||||
@implementation TFGiftAlertView
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
self.alertBtnType = TFAlertButtonTypeSingleConfirm;
|
||||
}
|
||||
|
||||
- (void)setAlertModel:(WXYZ_TickectAlertModel *)alertModel giftModel:(WXYZ_GiftMonthlyPassListModel *)giftModel production_id:(NSInteger)production_id ticketBlock:(void(^)(NSInteger number))ticketBlock
|
||||
{
|
||||
self.alertTitle = alertModel.title ? : @"";
|
||||
|
||||
NSString *str = [alertModel.desc componentsJoinedByString:@"\n"];
|
||||
NSRange range = [str rangeOfString:@"###.*###" options:NSRegularExpressionSearch];
|
||||
if (range.length == 0) range = NSMakeRange(0, 0);
|
||||
NSString *suffix = [[str substringWithRange:range] stringByReplacingOccurrencesOfString:@"#" withString:@""];
|
||||
NSMutableString *prefix = [NSMutableString stringWithString:[str stringByReplacingCharactersInRange:range withString:@""]];
|
||||
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
|
||||
style.lineSpacing = 9.0;
|
||||
[prefix insertString:suffix atIndex:range.location];
|
||||
|
||||
NSMutableAttributedString *t_atr = [[NSMutableAttributedString alloc] initWithString:prefix attributes:@{NSFontAttributeName : kFont13, NSForegroundColorAttributeName : kGrayTextColor, NSParagraphStyleAttributeName : style}];
|
||||
[t_atr addAttributes:@{NSForegroundColorAttributeName : kMainColor} range:NSMakeRange(range.location, suffix.length)];
|
||||
t_atr.alignment = NSTextAlignmentCenter;
|
||||
self.attributedStr = t_atr;
|
||||
self.confirmTitle = alertModel.items.firstObject.title ?: @"";
|
||||
|
||||
[self.contentScrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.alertTitleLabel.mas_bottom).offset(0);
|
||||
make.left.equalTo(self.alertBackView).offset(kHalfMargin);
|
||||
make.right.equalTo(self.alertBackView).offset(-kHalfMargin);
|
||||
make.height.mas_equalTo([TFViewHelper getDynamicHeightWithLabelFont:kMainFont labelWidth:SCREEN_WIDTH - 3 * kMargin labelText:self.attributedStr.string] + kLabelHeight);
|
||||
}];
|
||||
self.contentScrollView.scrollEnabled = NO;
|
||||
|
||||
[self.alertBackView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.alertBackView.superview).offset(kMargin * 2);
|
||||
make.right.equalTo(self.alertBackView.superview).offset(-kMargin * 2);
|
||||
make.bottom.mas_equalTo(self.confirmButton.mas_bottom).with.offset(0).priorityLow();
|
||||
make.center.equalTo(self.alertBackView.superview);
|
||||
}];
|
||||
|
||||
[self.contentLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.left.right.bottom.equalTo(self.contentScrollView);
|
||||
}];
|
||||
|
||||
[self.confirmButton mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.alertBackView.mas_right).with.offset(0);
|
||||
make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(kHalfMargin);
|
||||
make.height.mas_equalTo(45.0);
|
||||
make.width.equalTo(self.alertBackView);
|
||||
}];
|
||||
|
||||
self.confirmButtonClickBlock = ^{
|
||||
if ([alertModel.items.firstObject.action isEqualToString:@"recharge"]) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@""];
|
||||
[[TFViewHelper getCurrentNavigationController] pushViewController:[[TFRechargeViewController alloc] init] animated:YES];
|
||||
} else {
|
||||
NSDictionary *params = @{
|
||||
@"book_id" : @(production_id),
|
||||
@"chapter_id" : @([TFReaderBookManager sharedManager].chapter_id),
|
||||
@"num" : @(giftModel.num),
|
||||
@"use_gold" : @"1"
|
||||
};
|
||||
[TFNetworkTools POST:Book_Reward_Ticket_Vote parameters:params model:nil success:^(BOOL isSuccess, NSDictionary * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
|
||||
if (isSuccess) {
|
||||
NSString *text = [NSString stringWithFormat:@"%@", t_model[@"data"][@"ticket_num"]];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeTicket" object:text];
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"投票成功")];
|
||||
[TFReaderBookManager sharedManager].ticket_num = text ?: @"";
|
||||
!ticketBlock ?: ticketBlock([text integerValue]);
|
||||
} else {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[TFPromptManager showPromptWithError:error defaultText:nil];
|
||||
}];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// TFSignAlertView.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TFAlertView.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TFSignAlertView : TFAlertView
|
||||
|
||||
@property (nonatomic ,strong) NSArray *bookList;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,200 @@
|
||||
//
|
||||
// TFSignAlertView.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFSignAlertView.h"
|
||||
#import "TFCollectionManager.h"
|
||||
|
||||
@interface TFSignAlertView ()
|
||||
|
||||
@property (nonatomic ,strong) UIView *bookBackView;
|
||||
@end
|
||||
|
||||
@implementation TFSignAlertView
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
self.bookBackView = [[UIView alloc] init];
|
||||
self.bookBackView.backgroundColor = [UIColor clearColor];
|
||||
[self.alertBackView addSubview:self.bookBackView];
|
||||
|
||||
self.cancelTitle = TFLocalizedString(@"不用了");
|
||||
self.confirmTitle = TFLocalizedString(@"全部加入书架");
|
||||
|
||||
WS(weakSelf)
|
||||
self.confirmButtonClickBlock = ^{
|
||||
[weakSelf addBooks];
|
||||
};
|
||||
}
|
||||
|
||||
- (void)showAlertView
|
||||
{
|
||||
if (_bookList.count == 0) {
|
||||
[self closeAlertView];
|
||||
return;
|
||||
}
|
||||
|
||||
[super showAlertView];
|
||||
|
||||
CGFloat bookWidth = (self.alertViewWidth - 2 * kMargin - 2 * kHalfMargin) / 3;
|
||||
CGFloat bookHeigh = kGeometricHeight(bookWidth, 3, 4);
|
||||
|
||||
[self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(30);
|
||||
}];
|
||||
|
||||
[self.bookBackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(kMargin);
|
||||
make.top.mas_equalTo(self.contentLabel.mas_bottom).with.offset(kMargin);
|
||||
make.width.mas_equalTo(self.alertBackView.mas_width).with.offset(- 2 * kMargin);
|
||||
make.height.mas_equalTo(bookHeigh + 40);
|
||||
}];
|
||||
|
||||
[self.cancelButton mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.alertBackView.mas_left).with.offset(0);
|
||||
make.top.mas_equalTo(self.bookBackView.mas_bottom).with.offset(kMargin);
|
||||
make.height.mas_equalTo(self.alertViewBtnHeight);
|
||||
make.width.mas_equalTo(self.alertViewWidth / 2);
|
||||
}];
|
||||
|
||||
[self.confirmButton mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.alertBackView.mas_right).with.offset(0);
|
||||
make.top.mas_equalTo(self.bookBackView.mas_bottom).with.offset(kMargin);
|
||||
make.height.mas_equalTo(self.alertViewBtnHeight);
|
||||
make.width.mas_equalTo(self.alertViewWidth / 2);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setBookList:(NSArray *)bookList
|
||||
{
|
||||
_bookList = bookList;
|
||||
if (kObjectIsEmpty(bookList)) return;
|
||||
|
||||
CGFloat bookWidth = (self.alertViewWidth - (2 * kMargin) - (2 * kHalfMargin)) / 3.0;
|
||||
CGFloat bookHeigh = kGeometricHeight(bookWidth, 3, 4);
|
||||
|
||||
int buttonNum = 3;//每行多少按钮
|
||||
CGFloat button_W = bookWidth;//按钮宽
|
||||
CGFloat space_X = kHalfMargin;//按钮间距
|
||||
UIView *backView = [[UIView alloc] init];
|
||||
backView.backgroundColor = [UIColor clearColor];
|
||||
[self.bookBackView addSubview:backView];
|
||||
[backView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.center.equalTo(self.bookBackView);
|
||||
}];
|
||||
|
||||
int max = (int)(bookList.count < 3 ? bookList.count : 3);
|
||||
|
||||
for (int i = 0; i < max; i ++) {
|
||||
int loc = i % buttonNum;//列号
|
||||
CGFloat button_X = (space_X + button_W) * loc;
|
||||
|
||||
TFProductionModel *t_model = [bookList objectOrNilAtIndex:i];
|
||||
|
||||
// 图片
|
||||
TFProductionCoverView *bookImageView = [[TFProductionCoverView alloc] initWithProductionType:t_model.productionType coverDirection:TFProductionCoverDirectionVertical];
|
||||
bookImageView.userInteractionEnabled = YES;
|
||||
bookImageView.coverImageUrl = t_model.cover;
|
||||
[backView addSubview:bookImageView];
|
||||
|
||||
[bookImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(0);
|
||||
make.left.mas_equalTo(button_X);
|
||||
make.width.mas_equalTo(bookWidth);
|
||||
make.height.mas_equalTo(bookHeigh);
|
||||
if (i == max - 1) {
|
||||
make.right.equalTo(backView);
|
||||
}
|
||||
}];
|
||||
|
||||
// 书名
|
||||
UILabel *titleLabel = [[UILabel alloc] init];
|
||||
titleLabel.numberOfLines = 1;
|
||||
titleLabel.text = [NSString stringWithFormat:@"%@\n", t_model.name];
|
||||
titleLabel.backgroundColor = kWhiteColor;
|
||||
titleLabel.font = kFont12;
|
||||
titleLabel.textAlignment = NSTextAlignmentLeft;
|
||||
[backView addSubview:titleLabel];
|
||||
|
||||
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(bookImageView.mas_centerX);
|
||||
make.top.mas_equalTo(bookImageView.mas_bottom);
|
||||
make.width.mas_equalTo(bookImageView.mas_width);
|
||||
make.height.mas_equalTo(20);
|
||||
make.bottom.equalTo(backView);
|
||||
}];
|
||||
|
||||
UILabel *connerLabel = [[UILabel alloc] init];
|
||||
connerLabel.font = kFont8;
|
||||
connerLabel.layer.cornerRadius = 4.0f;
|
||||
connerLabel.textAlignment = NSTextAlignmentCenter;
|
||||
connerLabel.textColor = kWhiteColor;
|
||||
connerLabel.clipsToBounds = YES;
|
||||
[bookImageView addSubview:connerLabel];
|
||||
|
||||
[connerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(bookImageView.mas_right).with.offset(- kQuarterMargin);
|
||||
make.top.mas_equalTo(bookImageView.mas_top).with.offset(kQuarterMargin);
|
||||
make.width.mas_equalTo(30);
|
||||
make.height.mas_equalTo(15);
|
||||
}];
|
||||
|
||||
if (t_model.productionType == TFProductionTypeNovel) {
|
||||
connerLabel.backgroundColor = kMainColor;
|
||||
connerLabel.text = TFLocalizedString(@"小说");
|
||||
[connerLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:connerLabel]);
|
||||
}];
|
||||
}
|
||||
|
||||
if (t_model.productionType == TFProductionTypeComic) {
|
||||
connerLabel.backgroundColor = kRedColor;
|
||||
connerLabel.text = TFLocalizedString(@"漫画");
|
||||
[connerLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:connerLabel]);
|
||||
}];
|
||||
}
|
||||
|
||||
if (t_model.productionType == TFProductionTypeAudio) {
|
||||
connerLabel.backgroundColor = [UIColor colorWithHexString:@"#56a0ef"];
|
||||
connerLabel.text = TFLocalizedString(@"听书");
|
||||
[connerLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:connerLabel]);
|
||||
}];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)addBooks
|
||||
{
|
||||
for (TFProductionModel *t_model in self.bookList) {
|
||||
switch (t_model.productionType) {
|
||||
case TFProductionTypeNovel:
|
||||
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] addCollectionWithProductionModel:t_model atIndex:0];
|
||||
break;
|
||||
|
||||
case TFProductionTypeComic:
|
||||
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] addCollectionWithProductionModel:t_model];
|
||||
break;
|
||||
|
||||
case TFProductionTypeAudio:
|
||||
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] addCollectionWithProductionModel:t_model];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (self.bookList) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Reload_Rack_Production object:nil];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// TFTextFieldAlertView.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TFAlertView.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TFTextFieldAlertView : TFAlertView
|
||||
|
||||
@property (nonatomic ,copy) void(^endEditedBlock)(NSString *inputText);
|
||||
|
||||
@property (nonatomic ,copy) NSString *placeHoldTitle;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,107 @@
|
||||
//
|
||||
// TFTextFieldAlertView.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFTextFieldAlertView.h"
|
||||
#import "TFKeyboardManager.h"
|
||||
|
||||
@interface TFTextFieldAlertView ()
|
||||
|
||||
@property (nonatomic ,strong) UITextField *textField;
|
||||
@property (nonatomic ,strong) TFKeyboardManager *keyboardManager;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFTextFieldAlertView
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
self.textField = [[UITextField alloc] init];
|
||||
self.textField.backgroundColor = [UIColor clearColor];
|
||||
self.textField.font = kMainFont;
|
||||
self.textField.textColor = [UIColor blackColor];
|
||||
self.textField.textAlignment = NSTextAlignmentLeft;
|
||||
self.textField.clearButtonMode = UITextFieldViewModeWhileEditing;
|
||||
self.textField.layer.borderColor = kColorRGBA(235, 235, 241, 1).CGColor;
|
||||
self.textField.layer.borderWidth = 1;
|
||||
self.textField.layer.cornerRadius = 8;
|
||||
self.textField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 20)];
|
||||
self.textField.leftViewMode = UITextFieldViewModeAlways;
|
||||
[self.alertBackView addSubview:self.textField];
|
||||
|
||||
[self.confirmButton addTarget:self action:@selector(confirmButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
WS(weakSelf)
|
||||
self.keyboardManager = [[TFKeyboardManager alloc] initObserverWithAdaptiveMovementView:self.alertBackView];
|
||||
self.keyboardManager.spacingFromKeyboard = 80;
|
||||
self.keyboardManager.keyboardHeightChanged = ^(CGFloat keyboardHeight, CGFloat shouldMoveDistance, CGRect shouldMoveFrame) {
|
||||
weakSelf.alertBackView.frame = shouldMoveFrame;
|
||||
};
|
||||
}
|
||||
|
||||
- (void)showAlertView
|
||||
{
|
||||
[super showAlertView];
|
||||
|
||||
[self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.alertTitleLabel.mas_left);
|
||||
make.right.mas_equalTo(self.alertTitleLabel.mas_right);
|
||||
make.top.mas_equalTo(self.contentScrollView.mas_bottom).with.offset(kHalfMargin);
|
||||
make.height.mas_equalTo(self.alertViewBtnHeight);
|
||||
}];
|
||||
|
||||
[self.cancelButton mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.alertBackView.mas_left).with.offset(0);
|
||||
make.top.mas_equalTo(self.textField.mas_bottom).with.offset(kMargin);
|
||||
make.height.mas_equalTo(self.alertViewBtnHeight);
|
||||
make.width.mas_equalTo(self.alertViewWidth / 2);
|
||||
}];
|
||||
|
||||
[self.confirmButton mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.alertBackView.mas_right).with.offset(0);
|
||||
make.top.mas_equalTo(self.textField.mas_bottom).with.offset(kMargin);
|
||||
make.height.mas_equalTo(self.alertViewBtnHeight);
|
||||
make.width.mas_equalTo(self.alertViewWidth / 2);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setPlaceHoldTitle:(NSString *)placeHoldTitle
|
||||
{
|
||||
_placeHoldTitle = placeHoldTitle;
|
||||
|
||||
self.textField.text = placeHoldTitle;
|
||||
}
|
||||
|
||||
- (void)confirmButtonClick
|
||||
{
|
||||
self.textField.text = [self.textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
|
||||
if (self.textField.text.length == 0) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"昵称不能为空")];
|
||||
return;
|
||||
}
|
||||
|
||||
if ([self.placeHoldTitle isEqualToString:self.textField.text]) {
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"昵称没有变化哦")];
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.endEditedBlock) {
|
||||
self.endEditedBlock(self.textField.text);
|
||||
}
|
||||
[self closeAlertView];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self.keyboardManager stopKeyboardObserver];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// TFUpdateAlertView.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TFAlertView.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TFUpdateAlertView : TFAlertView
|
||||
|
||||
@property (nonatomic ,copy) NSString *updateMessage;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,107 @@
|
||||
//
|
||||
// TFUpdateAlertView.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/17.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFUpdateAlertView.h"
|
||||
|
||||
@interface TFUpdateAlertView ()
|
||||
|
||||
@property (nonatomic ,strong) UIImageView *topImageView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFUpdateAlertView
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
self.closeButton.hidden = YES;
|
||||
self.showDivider = NO;
|
||||
self.contentScrollView.showsVerticalScrollIndicator = YES;
|
||||
|
||||
[self addSubview:self.alertBackView];
|
||||
|
||||
self.topImageView = [[UIImageView alloc] init];
|
||||
self.topImageView.image = [UIImage imageNamed:TFLocalizedString(@"alert_update_top")];
|
||||
[self.alertBackView addSubview:self.topImageView];
|
||||
[self.alertBackView sendSubviewToBack:self.topImageView];
|
||||
|
||||
self.alertTitle = @"";
|
||||
self.contentLabel.textAlignment = NSTextAlignmentLeft;
|
||||
|
||||
self.cancelButton.backgroundColor = [UIColor clearColor];
|
||||
[self.cancelButton setTitleColor:kColorRGBA(62, 120, 232, 1) forState:UIControlStateNormal];
|
||||
self.cancelTitle = TFLocalizedString(@"再等等");
|
||||
|
||||
self.confirmButton.layer.cornerRadius = self.alertViewBtnHeight / 2;
|
||||
self.confirmButton.backgroundColor = kColorRGBA(62, 120, 232, 1);
|
||||
[self.confirmButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
|
||||
[self.alertBackView addSubview:self.confirmButton];
|
||||
self.confirmTitle = TFLocalizedString(@"去更新");
|
||||
}
|
||||
|
||||
- (void)showAlertView
|
||||
{
|
||||
[super showAlertView];
|
||||
|
||||
[self.alertBackView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(self.confirmButton.mas_bottom).with.offset(kMargin);
|
||||
make.centerY.mas_equalTo(self.mas_centerY).with.offset(self.alertViewWidth * 0.12);
|
||||
}];
|
||||
|
||||
[self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(self.alertBackView.mas_width);
|
||||
make.height.mas_equalTo(self.alertBackView.mas_width).with.multipliedBy(0.4788);
|
||||
make.centerX.mas_equalTo(self.alertBackView.mas_centerX);
|
||||
make.bottom.mas_equalTo(self.alertBackView.mas_top).with.offset(kMargin);
|
||||
}];
|
||||
|
||||
CGFloat labelHeight = [TFViewHelper getDynamicHeightWithLabelFont:kMainFont labelWidth:SCREEN_WIDTH - 3 * kMargin labelText:self.alertDetailContent] + kMargin;
|
||||
|
||||
if (labelHeight < self.alertViewWidth * 0.24) {
|
||||
labelHeight = self.alertViewWidth * 0.24;
|
||||
[self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(labelHeight);
|
||||
}];
|
||||
} else if (labelHeight > SCREEN_HEIGHT / 3) {
|
||||
labelHeight = SCREEN_HEIGHT / 3;
|
||||
}
|
||||
|
||||
[self.contentScrollView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(labelHeight);
|
||||
}];
|
||||
|
||||
[self.cancelButton mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.alertBackView.mas_left).with.offset(kMargin);
|
||||
if (self.alertBtnType == TFAlertButtonTypeSingleConfirm) {
|
||||
make.width.mas_equalTo(CGFLOAT_MIN);
|
||||
} else {
|
||||
make.width.mas_equalTo(self.alertViewWidth / 2 - kMargin - kHalfMargin);
|
||||
}
|
||||
}];
|
||||
|
||||
[self.confirmButton mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.alertBackView.mas_right).with.offset(- kMargin);
|
||||
if (self.alertBtnType == TFAlertButtonTypeSingleCancel) {
|
||||
make.width.mas_equalTo(CGFLOAT_MIN);
|
||||
} else if (self.alertBtnType == TFAlertButtonTypeSingleConfirm) {
|
||||
make.width.mas_equalTo(self.alertViewWidth - 2 * kMargin);
|
||||
} else {
|
||||
make.width.mas_equalTo(self.alertViewWidth / 2 - kMargin - kHalfMargin);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setUpdateMessage:(NSString *)updateMessage
|
||||
{
|
||||
_updateMessage = updateMessage;
|
||||
|
||||
self.alertDetailContent = updateMessage;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user