chore: Initial clean commit
- Removed YuMi/Library/ (138 MB, not tracked) - Removed YuMi/Resources/ (23 MB, not tracked) - Removed old version assets (566 files, not tracked) - Excluded Pods/, xcuserdata/ and other build artifacts - Clean repository optimized for company server deployment
This commit is contained in:
60
YuMi/CustomUI/TTPopup/Config/TTActionSheetConfig.h
Normal file
60
YuMi/CustomUI/TTPopup/Config/TTActionSheetConfig.h
Normal file
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// TTActionSheetConfig.h
|
||||
// AFNetworking
|
||||
//
|
||||
// Created by lee on 2019/5/23.
|
||||
// action sheet item 配置
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
typedef enum : NSUInteger {
|
||||
TTItemSelectNormal,
|
||||
TTItemSelectHighLight,
|
||||
} TTItemSelectType;
|
||||
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
typedef void(^TTActionSheetClickAction)(void);
|
||||
|
||||
@interface TTActionSheetConfig : NSObject
|
||||
|
||||
/** 标题 */
|
||||
@property (nonatomic, copy) NSString *title;
|
||||
|
||||
/**
|
||||
标题颜色
|
||||
*/
|
||||
@property (nonatomic, strong) UIColor *titleColor;
|
||||
|
||||
/** 是否选中 */
|
||||
@property (nonatomic, assign) TTItemSelectType type;
|
||||
|
||||
/** 点击事件 */
|
||||
@property (nonatomic, copy) TTActionSheetClickAction clickAction;
|
||||
|
||||
@property(nonatomic, assign) BOOL displayMoliCoin;
|
||||
|
||||
/**
|
||||
构建 actionSheet item 实例
|
||||
|
||||
@param title 标题
|
||||
@param clickAction 点击事件
|
||||
@return item 实例
|
||||
*/
|
||||
+ (TTActionSheetConfig *)normalTitle:(NSString *)title
|
||||
clickAction:(TTActionSheetClickAction)clickAction;
|
||||
+ (TTActionSheetConfig *)normalTitle:(NSString *)title
|
||||
selectColorType:(TTItemSelectType)type clickAction:(TTActionSheetClickAction)clickAction;
|
||||
|
||||
|
||||
/// 构建实例
|
||||
/// @param title 标题
|
||||
/// @param textColor 颜色
|
||||
/// @param handler 事件处理
|
||||
+ (TTActionSheetConfig *)actionWithTitle:(NSString *)title
|
||||
color:(UIColor *)textColor
|
||||
handler:(TTActionSheetClickAction)handler;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
49
YuMi/CustomUI/TTPopup/Config/TTActionSheetConfig.m
Normal file
49
YuMi/CustomUI/TTPopup/Config/TTActionSheetConfig.m
Normal file
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// TTActionSheetConfig.m
|
||||
// AFNetworking
|
||||
//
|
||||
// Created by lee on 2019/5/23.
|
||||
//
|
||||
|
||||
#import "TTActionSheetConfig.h"
|
||||
#import "DJDKMIMOMColor.h"
|
||||
|
||||
@implementation TTActionSheetConfig
|
||||
|
||||
/**
|
||||
构建 actionSheet item 实例
|
||||
|
||||
@param title 标题
|
||||
@param clickAction 点击事件
|
||||
@return item 实例
|
||||
*/
|
||||
+ (TTActionSheetConfig *)normalTitle:(NSString *)title clickAction:(TTActionSheetClickAction)clickAction {
|
||||
|
||||
return [self normalTitle:title selectColorType:TTItemSelectNormal clickAction:clickAction];
|
||||
}
|
||||
|
||||
+ (TTActionSheetConfig *)normalTitle:(NSString *)title selectColorType:(TTItemSelectType)type clickAction:(TTActionSheetClickAction)clickAction {
|
||||
|
||||
UIColor *color = type == TTItemSelectHighLight ? [DJDKMIMOMColor alertTitleColor] : [DJDKMIMOMColor alertTitleColor];
|
||||
|
||||
TTActionSheetConfig *config = [self actionWithTitle:title color:color handler:clickAction];
|
||||
config.type = type;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
+ (TTActionSheetConfig *)actionWithTitle:(NSString *)title
|
||||
color:(UIColor *)textColor
|
||||
handler:(TTActionSheetClickAction)handler {
|
||||
|
||||
TTActionSheetConfig *config = [[TTActionSheetConfig alloc] init];
|
||||
config.type = TTItemSelectNormal;
|
||||
config.title = title;
|
||||
config.titleColor = textColor;
|
||||
config.clickAction = handler;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@end
|
30
YuMi/CustomUI/TTPopup/Config/TTAlertButtonConfig.h
Normal file
30
YuMi/CustomUI/TTPopup/Config/TTAlertButtonConfig.h
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// TTAlertButtonConfig.h
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lee on 2019/5/21.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
// alert 按钮配置
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TTAlertButtonConfig : NSObject
|
||||
/** 按钮标题 */
|
||||
@property (nonatomic, copy) NSString *title;
|
||||
/** 按钮字体 */
|
||||
@property (nonatomic, strong) UIFont *font;
|
||||
/** 按钮字体颜色 */
|
||||
@property (nonatomic, strong) UIColor *titleColor;
|
||||
/** 背景色 */
|
||||
@property (nonatomic, strong) UIColor *backgroundColor;
|
||||
/** 背景图 */
|
||||
@property (nonatomic, strong) UIImage *backgroundImage;
|
||||
/** 圆角 */
|
||||
@property (nonatomic, assign) CGFloat cornerRadius;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
13
YuMi/CustomUI/TTPopup/Config/TTAlertButtonConfig.m
Normal file
13
YuMi/CustomUI/TTPopup/Config/TTAlertButtonConfig.m
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// TTAlertButtonConfig.m
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lee on 2019/5/21.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TTAlertButtonConfig.h"
|
||||
|
||||
@implementation TTAlertButtonConfig
|
||||
|
||||
@end
|
86
YuMi/CustomUI/TTPopup/Config/TTAlertConfig.h
Normal file
86
YuMi/CustomUI/TTPopup/Config/TTAlertConfig.h
Normal file
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// TTAlertConfig.h
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lee on 2019/5/20.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
// alert 配置
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TTAlertButtonConfig.h"
|
||||
#import "TTAlertMessageAttributedConfig.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef NS_ENUM(NSUInteger, TTAlertActionStyle) {
|
||||
TTAlertActionConfirmStyle = 0, // 只有确定按钮
|
||||
TTAlertActionCancelStyle = 1, // 只有取消按钮
|
||||
TTAlertActionBothStyle = 2, // 全部按钮
|
||||
};
|
||||
|
||||
|
||||
@interface TTAlertConfig : NSObject
|
||||
// 按钮显示风格
|
||||
@property (nonatomic, assign) TTAlertActionStyle actionStyle;
|
||||
// 容器背景设置
|
||||
@property (nonatomic, strong) UIColor *backgroundColor;
|
||||
|
||||
// 标题设置
|
||||
@property (nonatomic, copy) NSString *title;
|
||||
@property (nonatomic, strong) UIFont *titleFont;
|
||||
@property (nonatomic, strong) UIColor *titleColor;
|
||||
|
||||
// 内容设置
|
||||
@property (nonatomic, copy) NSString *message;
|
||||
@property (nonatomic, strong) UIFont *messageFont;
|
||||
@property (nonatomic, strong) UIColor *messageColor;
|
||||
/** 内容的行间距,默认不设置,当值为 0 或负数时无效 */
|
||||
@property (nonatomic, assign) CGFloat messageLineSpacing;
|
||||
@property(nonatomic, assign) NSTextAlignment messageTextAlignment;
|
||||
/** 内容富文本配置 */
|
||||
@property (nonatomic, strong) NSArray<TTAlertMessageAttributedConfig *> *messageAttributedConfig;
|
||||
///配置内容的富文本
|
||||
@property (nonatomic,strong) NSMutableAttributedString *messageAttributed;
|
||||
|
||||
// 取消按钮配置
|
||||
@property (nonatomic, strong) TTAlertButtonConfig *cancelButtonConfig;
|
||||
|
||||
// 确定按钮配置
|
||||
@property (nonatomic, strong) TTAlertButtonConfig *confirmButtonConfig;
|
||||
|
||||
/**
|
||||
背景蒙层的透明度
|
||||
@Description 默认是 000000 黑色 0.3 alpha
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat maskBackgroundAlpha;
|
||||
|
||||
// 圆角
|
||||
@property (nonatomic, assign) CGFloat cornerRadius;
|
||||
|
||||
// 点击蒙层是否消失,默认:YES
|
||||
@property (nonatomic, assign) BOOL shouldDismissOnBackgroundTouch;
|
||||
|
||||
/**
|
||||
点击‘确定’‘取消’按钮时禁止弹窗自动消失,默认:NO
|
||||
|
||||
@discussion 若值为 YES,需要主动调用 [TTPopup dismiss] 消除弹窗
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL disableAutoDismissWhenClickButton;
|
||||
|
||||
/**
|
||||
重复弹窗过滤,默认:NO
|
||||
|
||||
@discussion 设置过滤时,队列中将不会出现相同过滤标识的弹窗
|
||||
过滤标识通过 #<filterIdentifier> 设置
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL shouldFilterPopup;
|
||||
|
||||
/**
|
||||
过滤标识,默认:nil
|
||||
*/
|
||||
@property (nonatomic, copy) NSString *filterIdentifier;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
90
YuMi/CustomUI/TTPopup/Config/TTAlertConfig.m
Normal file
90
YuMi/CustomUI/TTPopup/Config/TTAlertConfig.m
Normal file
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// TTAlertConfig.m
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lee on 2019/5/20.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TTAlertConfig.h"
|
||||
#import "UIImage+Utils.h"
|
||||
#import "DJDKMIMOMColor.h"
|
||||
|
||||
static CGFloat kAlertTitleFont = 18.f;
|
||||
static CGFloat kAlertButtonFont = 15.f;
|
||||
static CGFloat kAlertMessageFont = 15.f;
|
||||
static CGFloat kAlertCornerRadius = 12.f;
|
||||
static CGFloat kAlertBackgroundColorAlpha = 0.3;
|
||||
static CGFloat kAlertMessageFontLineSpace = -1;
|
||||
static CGFloat kAlertButtonCornerRadius = 8.f;
|
||||
|
||||
@implementation TTAlertConfig
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
|
||||
_backgroundColor = [DJDKMIMOMColor alertBackgroundColor];
|
||||
|
||||
//背景颜色
|
||||
kAlertTitleFont = 16.f;
|
||||
kAlertCornerRadius = 14.f;
|
||||
kAlertButtonCornerRadius = 19.f;
|
||||
|
||||
_actionStyle = TTAlertActionBothStyle;
|
||||
|
||||
// title
|
||||
_title = @"";// 标题
|
||||
_titleFont = [UIFont fontWithName:@"PingFangSC-Medium" size:kAlertTitleFont];// 字体
|
||||
_titleColor = [DJDKMIMOMColor alertTitleColor];// 颜色
|
||||
|
||||
// message
|
||||
_message = @"";
|
||||
_messageFont = [UIFont systemFontOfSize:kAlertMessageFont];// 内容
|
||||
_messageColor = [DJDKMIMOMColor alertMessageColor];// 颜色
|
||||
_messageLineSpacing = kAlertMessageFontLineSpace;// 字体行间距
|
||||
_messageAttributedConfig = @[];// 自定义富文本样式
|
||||
_messageTextAlignment = NSTextAlignmentCenter;
|
||||
|
||||
// cancel button
|
||||
_cancelButtonConfig = [[TTAlertButtonConfig alloc] init];
|
||||
_cancelButtonConfig.title = YMLocalizedString(@"XPRoomSettingInputView4");// 取消按钮
|
||||
_cancelButtonConfig.font = [UIFont systemFontOfSize:kAlertButtonFont];// 按钮字体
|
||||
_cancelButtonConfig.titleColor = [DJDKMIMOMColor cancelButtonTextColor];// 字体颜色
|
||||
_cancelButtonConfig.backgroundImage = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor cancelButtonGradientStartColor], [DJDKMIMOMColor cancelButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)];
|
||||
_cancelButtonConfig.cornerRadius = kAlertButtonCornerRadius;// 按钮背景图
|
||||
|
||||
|
||||
// confirm button
|
||||
_confirmButtonConfig = [[TTAlertButtonConfig alloc] init];
|
||||
_confirmButtonConfig.title = YMLocalizedString(@"TTAlertConfig0");
|
||||
_confirmButtonConfig.font = [UIFont systemFontOfSize:kAlertButtonFont];
|
||||
_confirmButtonConfig.titleColor = [DJDKMIMOMColor confirmButtonTextColor];
|
||||
_confirmButtonConfig.backgroundImage = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xE29030), UIColorFromRGB(0xFCC074)]
|
||||
gradientType:GradientTypeLeftToRight
|
||||
imgSize:CGSizeMake(10, 10)];
|
||||
_confirmButtonConfig.cornerRadius = kAlertButtonCornerRadius;
|
||||
|
||||
// // 创建渐变图层
|
||||
// CAGradientLayer *gradientLayer = [CAGradientLayer layer];
|
||||
// gradientLayer.colors = @[(__bridge id)UIColorFromRGB(0xE29030).CGColor,
|
||||
// (__bridge id)UIColorFromRGB(0xFCC074).CGColor];
|
||||
// gradientLayer.startPoint = CGPointMake(0.0, 0.0); // 顶部中央
|
||||
// gradientLayer.endPoint = CGPointMake(0.0, 1.0); // 底部中央
|
||||
// gradientLayer.frame = CGRectMake(0, 0, 120, 38); // 设置渐变图层大小
|
||||
//
|
||||
// // 将渐变图层添加到按钮图层
|
||||
// [_previewActionButton.layer insertSublayer:gradientLayer atIndex:0];
|
||||
|
||||
_cornerRadius = kAlertCornerRadius;// 默认圆角
|
||||
_shouldDismissOnBackgroundTouch = YES;// 点击蒙层是否消失
|
||||
|
||||
// mask default 0.3 black
|
||||
_maskBackgroundAlpha = kAlertBackgroundColorAlpha; // alert 背景色
|
||||
_disableAutoDismissWhenClickButton = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// TTAlertContentAttributedConfig.h
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lee on 2019/5/21.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
// alert 提示内容富文本配置
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TTAlertMessageAttributedConfig : NSObject
|
||||
|
||||
/** 富文本字段需要特殊显示的文本 */
|
||||
@property (nonatomic, copy) NSString *text;
|
||||
|
||||
/** 颜色 */
|
||||
@property (nonatomic, strong) UIColor *color;
|
||||
|
||||
/** 字体 */
|
||||
@property (nonatomic, strong) UIFont *font;
|
||||
|
||||
/**
|
||||
目标文本指定位置,一旦设置则无视 text 的值
|
||||
|
||||
@discussion 内容文本中出现相同的目标文本时,可通过设置 range 精确指定位置
|
||||
*/
|
||||
@property (nonatomic, assign) NSRange range;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// TTAlertContentAttributedConfig.m
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lee on 2019/5/21.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TTAlertMessageAttributedConfig.h"
|
||||
|
||||
@implementation TTAlertMessageAttributedConfig
|
||||
|
||||
@end
|
38
YuMi/CustomUI/TTPopup/Header/TTPopupConstants.h
Normal file
38
YuMi/CustomUI/TTPopup/Header/TTPopupConstants.h
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// TTPopupConstants.h
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lvjunhang on 2019/5/21.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
/**
|
||||
Popup 组件通用回调
|
||||
*/
|
||||
typedef void(^TTPopupCompletionHandler)(void);
|
||||
|
||||
/**
|
||||
弹窗类型
|
||||
|
||||
- TTPopupStyleAlert: Alert
|
||||
- TTPopupStyleActionSheet: ActionSheet
|
||||
*/
|
||||
typedef NS_ENUM(NSUInteger, TTPopupStyle) {
|
||||
TTPopupStyleAlert = 0,
|
||||
TTPopupStyleActionSheet
|
||||
};
|
||||
|
||||
/**
|
||||
弹窗优先级
|
||||
|
||||
- TTPopupPriorityNormal: 普通
|
||||
- TTPopupPriorityHigh: 高
|
||||
- TTPopupPriorityRequired: 必须
|
||||
*/
|
||||
typedef NS_ENUM(NSUInteger, TTPopupPriority) {
|
||||
TTPopupPriorityNormal = 0,
|
||||
TTPopupPriorityHigh,
|
||||
TTPopupPriorityRequired
|
||||
};
|
24
YuMi/CustomUI/TTPopup/Manager/TTPopupManagerService.h
Normal file
24
YuMi/CustomUI/TTPopup/Manager/TTPopupManagerService.h
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// TTPopupManagerService.h
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lvjunhang on 2019/5/21.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "TTPopupManagerServiceProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TTPopupManagerService : NSObject<TTPopupManagerServiceProtocol>
|
||||
/**
|
||||
当前显示的弹窗服务
|
||||
*/
|
||||
@property (nonatomic, strong) id<TTPopupServiceProtocol> currentPopupService;
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
200
YuMi/CustomUI/TTPopup/Manager/TTPopupManagerService.m
Normal file
200
YuMi/CustomUI/TTPopup/Manager/TTPopupManagerService.m
Normal file
@@ -0,0 +1,200 @@
|
||||
//
|
||||
// TTPopupManagerService.m
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lvjunhang on 2019/5/21.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TTPopupManagerService.h"
|
||||
|
||||
#import <FFPopup/FFPopup.h>
|
||||
|
||||
@interface TTPopupManagerService ()
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray< id<TTPopupServiceProtocol> > *queue;
|
||||
/**
|
||||
当前是否正在显示状态
|
||||
*/
|
||||
@property (nonatomic, assign, getter=isShowingPopup) BOOL showingPopup;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TTPopupManagerService
|
||||
|
||||
#pragma mark - Life Cycle
|
||||
+ (instancetype)sharedInstance {
|
||||
static TTPopupManagerService *instance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
instance = [[self alloc] init];
|
||||
});
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_queue = [NSMutableArray array];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - TTPopupManagerServiceProtocol
|
||||
- (void)addPopupService:(id<TTPopupServiceProtocol>)service {
|
||||
if (![service conformsToProtocol:@protocol(TTPopupServiceProtocol)]) {
|
||||
return;
|
||||
}
|
||||
if ([_queue containsObject:service]) {
|
||||
return;
|
||||
}
|
||||
NSInteger insertPosition = [self insertPositionForPopupService:service];
|
||||
if (insertPosition == NSNotFound) {
|
||||
return;
|
||||
}
|
||||
[_queue insertObject:service atIndex:insertPosition];
|
||||
//当前没有弹窗显示且队列只有一个元素时,显示弹窗
|
||||
if (_currentPopupService == nil && _queue.count == 1) {
|
||||
[self showPopup];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removePopupService {
|
||||
|
||||
//防止当弹窗还未显示完成,在显示过程中频繁调用 dismiss
|
||||
//使得 _currentPopupService 被清空,导致弹窗无法消失,从而假死现象
|
||||
if (!self.isShowingPopup) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentPopupService == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_queue.count > 0) {
|
||||
[_queue removeObjectAtIndex:0];
|
||||
}
|
||||
|
||||
[FFPopup dismissPopupForView:_currentPopupService.contentView animated:YES];
|
||||
_currentPopupService = nil;
|
||||
}
|
||||
|
||||
/**
|
||||
点击蒙层时移除队列中的数据源
|
||||
|
||||
@discussion 注意无需调用 dismissPopupForView
|
||||
*/
|
||||
- (void)removeSourceWhenTouchMaskView {
|
||||
if (_currentPopupService == nil) {
|
||||
return;
|
||||
}
|
||||
if (_queue.count > 0) {
|
||||
[_queue removeObjectAtIndex:0];
|
||||
}
|
||||
_currentPopupService = nil;
|
||||
}
|
||||
|
||||
#pragma mark - Private Methods
|
||||
/**
|
||||
显示弹窗
|
||||
*/
|
||||
- (void)showPopup {
|
||||
if (self.isShowingPopup) {
|
||||
return;
|
||||
}
|
||||
if (_currentPopupService) {
|
||||
return;
|
||||
}
|
||||
if (_queue.count == 0) {
|
||||
return;
|
||||
}
|
||||
id<TTPopupServiceProtocol> popupService = _queue.firstObject;
|
||||
if (![popupService conformsToProtocol:@protocol(TTPopupServiceProtocol)]) {
|
||||
return;
|
||||
}
|
||||
_currentPopupService = popupService;
|
||||
FFPopupHorizontalLayout horizontalLayout = FFPopupHorizontalLayout_Center;
|
||||
FFPopupVerticalLayout verticalLayout = FFPopupVerticalLayout_Center;
|
||||
FFPopupShowType showType = (FFPopupShowType)popupService.showType;
|
||||
FFPopupDismissType dismissType = FFPopupDismissType_GrowOut;
|
||||
if (popupService.style == TTPopupStyleActionSheet) {
|
||||
verticalLayout = FFPopupVerticalLayout_Bottom;
|
||||
showType = FFPopupShowType_SlideInFromBottom;
|
||||
dismissType = FFPopupDismissType_SlideOutToBottom;
|
||||
}
|
||||
FFPopup *popup = [FFPopup popupWithContentView:popupService.contentView];
|
||||
popup.showType = showType;
|
||||
popup.dismissType = dismissType;
|
||||
popup.maskType = FFPopupMaskType_Dimmed;
|
||||
popup.dimmedMaskAlpha = popupService.maskBackgroundAlpha;
|
||||
popup.shouldDismissOnBackgroundTouch = popupService.shouldDismissOnBackgroundTouch;
|
||||
|
||||
[popup showWithLayout:FFPopupLayoutMake(horizontalLayout, verticalLayout) duration:0.0];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
// 不管是调用’dismissPopupForView:animated:‘ 还是‘点击蒙层消除’,最终都会走到这里
|
||||
// 适合在此展示队列中下一个弹窗
|
||||
// 通过 _currentPopupService 是否为空可以判断是哪种消除方式
|
||||
popup.didFinishDismissingBlock = ^{
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
BOOL isDismissOnBackgroundTouch = strongSelf.currentPopupService != nil;
|
||||
if (isDismissOnBackgroundTouch) {
|
||||
// ‘点击蒙层消除’时,在展现下一个弹窗前移除数据源
|
||||
[self removeSourceWhenTouchMaskView];
|
||||
}
|
||||
if (popupService.didFinishDismissHandler) {
|
||||
popupService.didFinishDismissHandler(isDismissOnBackgroundTouch);
|
||||
}
|
||||
// 弹窗消除结束,更新状态
|
||||
strongSelf.showingPopup = NO;
|
||||
// 显示下一个弹窗
|
||||
[strongSelf showPopup];
|
||||
};
|
||||
|
||||
popup.didFinishShowingBlock = ^{
|
||||
// 开始弹窗,更新状态
|
||||
self.showingPopup = YES;
|
||||
if (popupService.didFinishShowingHandler) {
|
||||
popupService.didFinishShowingHandler();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
弹窗将要插入队列的位置
|
||||
@param service 弹窗服务实例
|
||||
@return 队列的位置
|
||||
*/
|
||||
- (NSInteger)insertPositionForPopupService:(id<TTPopupServiceProtocol>)service {
|
||||
__block NSInteger result = NSNotFound;
|
||||
if (service == nil) {
|
||||
return result;
|
||||
}
|
||||
if (_queue.count == 0) {
|
||||
return 0;
|
||||
}
|
||||
// 设置重复弹窗过滤
|
||||
if (service.shouldFilterPopup && service.filterIdentifier.length > 0) {
|
||||
BOOL filterFlag = NO;
|
||||
for (id<TTPopupServiceProtocol> serv in _queue) {
|
||||
if ([serv.filterIdentifier isEqualToString:service.filterIdentifier]) {
|
||||
filterFlag = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (filterFlag) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
[_queue enumerateObjectsUsingBlock:^(id<TTPopupServiceProtocol> _Nonnull model, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
// 找到队中比当前弹窗优先级低的位置
|
||||
if (service.priority > model.priority) {
|
||||
result = idx;
|
||||
*stop = YES;
|
||||
}
|
||||
}];
|
||||
// 如果没有合适的位置,则将新的弹窗放在队尾
|
||||
result = MIN(result, _queue.count);
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// TTPopupManagerServiceProtocol.h
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lvjunhang on 2019/5/21.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TTPopupServiceProtocol.h"
|
||||
|
||||
@protocol TTPopupManagerServiceProtocol <NSObject>
|
||||
|
||||
/**
|
||||
添加一个弹窗
|
||||
|
||||
@param service 服从弹窗服务的实例
|
||||
*/
|
||||
- (void)addPopupService:(id<TTPopupServiceProtocol>)service;
|
||||
|
||||
/**
|
||||
移除一个弹窗
|
||||
*/
|
||||
- (void)removePopupService;
|
||||
|
||||
@end
|
22
YuMi/CustomUI/TTPopup/Service/TTPopupService.h
Normal file
22
YuMi/CustomUI/TTPopup/Service/TTPopupService.h
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// TTPopupService.h
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lvjunhang on 2019/5/21.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "TTPopupServiceProtocol.h"
|
||||
|
||||
// TTPopupConfig 是 TTPopupService 的别称
|
||||
// 具体信息见 TTPopupService
|
||||
#define TTPopupConfig TTPopupService
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TTPopupService : NSObject<TTPopupServiceProtocol>
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
36
YuMi/CustomUI/TTPopup/Service/TTPopupService.m
Normal file
36
YuMi/CustomUI/TTPopup/Service/TTPopupService.m
Normal file
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// TTPopupService.m
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lvjunhang on 2019/5/21.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TTPopupService.h"
|
||||
|
||||
@implementation TTPopupService
|
||||
|
||||
@synthesize style = _style;
|
||||
@synthesize priority = _priority;
|
||||
@synthesize contentView = _contentView;
|
||||
@synthesize maskBackgroundAlpha = _maskBackgroundAlpha;
|
||||
@synthesize shouldDismissOnBackgroundTouch = _shouldDismissOnBackgroundTouch;
|
||||
@synthesize didFinishDismissHandler = _didFinishDismissHandler;
|
||||
@synthesize didFinishShowingHandler = _didFinishShowingHandler;
|
||||
@synthesize shouldFilterPopup = _shouldFilterPopup;
|
||||
@synthesize filterIdentifier = _filterIdentifier;
|
||||
@synthesize showType = _showType;
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_style = TTPopupStyleAlert;
|
||||
_priority = TTPopupPriorityNormal;
|
||||
_maskBackgroundAlpha = 0.5;
|
||||
_shouldDismissOnBackgroundTouch = YES;
|
||||
_shouldFilterPopup = NO;
|
||||
_showType = TTPopupShowTypeDefault;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
78
YuMi/CustomUI/TTPopup/Service/TTPopupServiceProtocol.h
Normal file
78
YuMi/CustomUI/TTPopup/Service/TTPopupServiceProtocol.h
Normal file
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// TTPopupServiceProtocol.h
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lvjunhang on 2019/5/21.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TTPopupConstants.h"
|
||||
|
||||
typedef NS_ENUM(NSUInteger, TTPopupShowType) {
|
||||
TTPopupShowType_FadeIn = 1,
|
||||
TTPopupShowTypeDefault = 8,
|
||||
};
|
||||
|
||||
@class UIView;
|
||||
|
||||
@protocol TTPopupServiceProtocol <NSObject>
|
||||
|
||||
/**
|
||||
弹窗样式,默认:TTPopupStyleAlert
|
||||
*/
|
||||
@property (nonatomic, assign) TTPopupStyle style;
|
||||
|
||||
/**
|
||||
弹窗优先级权重,默认:TTPopupPriorityNormal
|
||||
|
||||
@discussion 权重越高在弹窗队列的优先级越高,即优先弹出;相同权重按先来后到原则
|
||||
*/
|
||||
@property (nonatomic, assign) TTPopupPriority priority;
|
||||
|
||||
/**
|
||||
自定义视图内容,默认:nil
|
||||
|
||||
@discussion 如果未配置,或 contentView 未继承自 UIView 及其子类,将忽略该弹窗
|
||||
*/
|
||||
@property (nonatomic, strong) UIView *contentView;
|
||||
|
||||
/**
|
||||
背景蒙层透明度,默认:0x000000 0.3 alpha
|
||||
|
||||
@discussion 由于第三方原因,暂不支持蒙层颜色修改
|
||||
*/
|
||||
@property (nonatomic, assign) CGFloat maskBackgroundAlpha;
|
||||
|
||||
/**
|
||||
点击蒙层是否消除弹窗,默认:YES
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL shouldDismissOnBackgroundTouch;
|
||||
|
||||
/**
|
||||
弹窗消失回调,isDismissOnBackgroundTouch 区分是否点击蒙层触发
|
||||
*/
|
||||
@property (nonatomic, copy) void (^didFinishDismissHandler)(BOOL isDismissOnBackgroundTouch);
|
||||
|
||||
/**
|
||||
弹窗显示成功回调
|
||||
*/
|
||||
@property (nonatomic, copy) void (^didFinishShowingHandler)(void);
|
||||
|
||||
/**
|
||||
重复弹窗过滤,默认:NO
|
||||
|
||||
@discussion 设置过滤时,队列中将不会出现相同过滤标识的弹窗
|
||||
过滤标识通过 #<filterIdentifier> 设置
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL shouldFilterPopup;
|
||||
|
||||
/**
|
||||
过滤标识,默认:nil
|
||||
*/
|
||||
@property (nonatomic, copy) NSString *filterIdentifier;
|
||||
|
||||
/**
|
||||
显示动画类型, 默认是 default
|
||||
*/
|
||||
@property (nonatomic, assign) TTPopupShowType showType;
|
||||
@end
|
126
YuMi/CustomUI/TTPopup/TTPopup.h
Normal file
126
YuMi/CustomUI/TTPopup/TTPopup.h
Normal file
@@ -0,0 +1,126 @@
|
||||
//
|
||||
// TTPopup.h
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lvjunhang on 2019/5/22.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
// 弹窗工具类
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "TTPopupConstants.h"
|
||||
#import "TTAlertConfig.h"
|
||||
#import "TTActionSheetConfig.h"
|
||||
#import "TTPopupService.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class UIView;
|
||||
|
||||
@interface TTPopup : NSObject
|
||||
|
||||
#pragma mark Alert
|
||||
/**
|
||||
显示 alert 弹窗
|
||||
|
||||
@discussion 显示四个内容:默认标题‘提示’,提示内容,取消按钮,确认按钮
|
||||
|
||||
@param message 提示内容,不能为空(⊙o⊙)哦
|
||||
@param confirmHandler 确认操作
|
||||
@param cancelHandler 取消操作
|
||||
*/
|
||||
+ (void)alertWithMessage:(NSString *)message
|
||||
confirmHandler:(TTPopupCompletionHandler)confirmHandler
|
||||
cancelHandler:(TTPopupCompletionHandler)cancelHandler;
|
||||
|
||||
|
||||
/**
|
||||
显示 alert 弹窗
|
||||
|
||||
@discussion 显示四个内容:默认标题‘提示’,提示内容,取消按钮,确认按钮
|
||||
|
||||
@param config 完善的视图配置,为您变态的需求保驾护航
|
||||
@param isShowBorder 是否显示边框
|
||||
@param confirmHandler 确认操作
|
||||
@param cancelHandler 取消操作
|
||||
*/
|
||||
+ (void)alertWithConfig:(TTAlertConfig *)config
|
||||
showBorder:(BOOL)isShowBorder
|
||||
confirmHandler:(TTPopupCompletionHandler)confirmHandler
|
||||
cancelHandler:(TTPopupCompletionHandler)cancelHandler;
|
||||
|
||||
|
||||
|
||||
+ (void)alertWithMessage:(NSString *)message
|
||||
config:(TTAlertConfig *)config
|
||||
showBorder:(BOOL)isShowBorder
|
||||
cancelHandler:(TTPopupCompletionHandler)cancelHandler
|
||||
confirmHandler:(TTPopupCompletionHandler)confirmHandler;
|
||||
|
||||
/**
|
||||
显示 alert 弹窗
|
||||
@discussion 显示四个内容:标题,提示内容,取消按钮,确认按钮
|
||||
@param config 完善的视图配置,为您变态的需求保驾护航
|
||||
@param cancelHandler 取消操作
|
||||
@param confirmHandler 确认操作
|
||||
*/
|
||||
+ (void)alertWithConfig:(TTAlertConfig *)config
|
||||
confirmHandler:(TTPopupCompletionHandler)confirmHandler
|
||||
cancelHandler:(TTPopupCompletionHandler)cancelHandler;
|
||||
|
||||
#pragma mark Action Sheet
|
||||
/**
|
||||
显示 action sheet 弹窗,自带贴心的取消按钮😊
|
||||
|
||||
@param items 配置列表
|
||||
*/
|
||||
+ (void)actionSheetWithItems:(NSArray<TTActionSheetConfig *> *)items;
|
||||
|
||||
/**
|
||||
显示 action sheet 弹窗
|
||||
|
||||
@param items 配置列表
|
||||
@param showCancelItem 是否显示取消按钮
|
||||
*/
|
||||
+ (void)actionSheetWithItems:(NSArray<TTActionSheetConfig *> *)items
|
||||
showCancelItem:(BOOL)showCancelItem;
|
||||
|
||||
/**
|
||||
显示 action sheet 弹窗
|
||||
|
||||
@param items 配置列表
|
||||
@param cancelHandler 取消按钮回调
|
||||
*/
|
||||
+ (void)actionSheetWithItems:(NSArray<TTActionSheetConfig *> *)items
|
||||
cancelHandler:(TTActionSheetClickAction)cancelHandler;
|
||||
|
||||
#pragma mark Popup
|
||||
/**
|
||||
显示自定义弹窗
|
||||
@param customView 自定义 view
|
||||
@param style 弹窗样式
|
||||
*/
|
||||
+ (void)popupView:(UIView *)customView
|
||||
style:(TTPopupStyle)style;
|
||||
|
||||
/**
|
||||
显示自定义弹窗
|
||||
|
||||
@param config 自定义弹窗配置
|
||||
*/
|
||||
+ (void)popupWithConfig:(TTPopupService *)config;
|
||||
|
||||
#pragma mark Dismiss
|
||||
/**
|
||||
消除当前弹窗
|
||||
*/
|
||||
+ (void)dismiss;
|
||||
|
||||
#pragma mark Query
|
||||
/**
|
||||
当前是否有显示弹窗
|
||||
*/
|
||||
+ (BOOL)hasShowPopup;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
243
YuMi/CustomUI/TTPopup/TTPopup.m
Normal file
243
YuMi/CustomUI/TTPopup/TTPopup.m
Normal file
@@ -0,0 +1,243 @@
|
||||
//
|
||||
// TTPopup.m
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lvjunhang on 2019/5/22.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TTPopup.h"
|
||||
#import "TTAlertView.h"
|
||||
#import "TTActionSheetView.h"
|
||||
#import "TTPopupService.h"
|
||||
#import "TTPopupManagerService.h"
|
||||
|
||||
static CGFloat const kActionSheetViewPadding = 15.f;
|
||||
static CGFloat const kActionSheetViewCellHeight = 52.f;
|
||||
static CGFloat const kActionSheetViewCancelViewHeight = 67.f;
|
||||
static CGFloat const kActionSheetViewBottomPadding = 15.f;
|
||||
static CGFloat const kMixHeight = 200.f;
|
||||
static CGFloat const kMaxHeight = 450.f;
|
||||
|
||||
@implementation TTPopup
|
||||
|
||||
#pragma mark - Public Methods
|
||||
#pragma mark Alert
|
||||
+ (void)alertWithMessage:(NSString *)message
|
||||
confirmHandler:(TTPopupCompletionHandler)confirmHandler
|
||||
cancelHandler:(TTPopupCompletionHandler)cancelHandler {
|
||||
|
||||
[self alertWithMessage:message
|
||||
config:nil
|
||||
cancelHandler:cancelHandler
|
||||
confirmHandler:confirmHandler];
|
||||
}
|
||||
|
||||
+ (void)alertWithConfig:(TTAlertConfig *)config
|
||||
confirmHandler:(TTPopupCompletionHandler)confirmHandler
|
||||
cancelHandler:(TTPopupCompletionHandler)cancelHandler {
|
||||
|
||||
[self alertWithMessage:nil
|
||||
config:config
|
||||
cancelHandler:cancelHandler
|
||||
confirmHandler:confirmHandler];
|
||||
}
|
||||
|
||||
+ (void)alertWithMessage:(NSString *)message
|
||||
config:(TTAlertConfig *)config
|
||||
cancelHandler:(TTPopupCompletionHandler)cancelHandler
|
||||
confirmHandler:(TTPopupCompletionHandler)confirmHandler {
|
||||
|
||||
if (!config) {
|
||||
config = [[TTAlertConfig alloc] init];
|
||||
config.title = YMLocalizedString(@"UserDetail_CP_Toast_0");
|
||||
config.message = message;
|
||||
}
|
||||
|
||||
if (config.message.length <= 0 && config.messageAttributed.length <=0 && config.messageAttributedConfig.count <=0) {
|
||||
#if DEBUG
|
||||
NSAssert(NO, @" message can not be nil, 弹窗文案不可以为空");
|
||||
return;
|
||||
#else
|
||||
// 防止正式环境 crash
|
||||
config.message = @" ";
|
||||
#endif
|
||||
}
|
||||
CGFloat width = [UIScreen mainScreen].bounds.size.width - 40 * 2;
|
||||
CGFloat height = ([self messageSize:config.message width:width].height + 160);
|
||||
// 最小 200, 最大 450
|
||||
if (height < kMixHeight) {
|
||||
height = kMixHeight;
|
||||
} else if (height > KScreenHeight - kSafeAreaTopHeight - kSafeAreaBottomHeight) {
|
||||
height = KScreenHeight - kSafeAreaTopHeight - kSafeAreaBottomHeight;
|
||||
}
|
||||
TTAlertView *contentView = [[TTAlertView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
|
||||
contentView.config = config;
|
||||
contentView.isConfigBoard = NO;
|
||||
contentView.cancelAction = cancelHandler;
|
||||
contentView.confirmAction = confirmHandler;
|
||||
if (!contentView.config.disableAutoDismissWhenClickButton) {
|
||||
// 设置弹窗按钮自动消除
|
||||
contentView.dismissAction = ^{
|
||||
[TTPopup dismiss];
|
||||
};
|
||||
}
|
||||
[self popupView:contentView style:TTPopupStyleAlert config:config];
|
||||
}
|
||||
|
||||
+ (void)alertWithConfig:(TTAlertConfig *)config
|
||||
showBorder:(BOOL)isShowBorder
|
||||
confirmHandler:(TTPopupCompletionHandler)confirmHandler
|
||||
cancelHandler:(TTPopupCompletionHandler)cancelHandler {
|
||||
[self alertWithMessage:@""
|
||||
config:config
|
||||
showBorder:isShowBorder
|
||||
cancelHandler:cancelHandler
|
||||
confirmHandler:confirmHandler];
|
||||
}
|
||||
|
||||
+ (void)alertWithMessage:(NSString *)message
|
||||
config:(TTAlertConfig *)config
|
||||
showBorder:(BOOL)isShowBorder
|
||||
cancelHandler:(TTPopupCompletionHandler)cancelHandler
|
||||
confirmHandler:(TTPopupCompletionHandler)confirmHandler {
|
||||
|
||||
if (!config) {
|
||||
config = [[TTAlertConfig alloc] init];
|
||||
config.message = message;
|
||||
}
|
||||
|
||||
if (config.message.length <= 0) {
|
||||
NSAssert(NO, @" message can not be nil, 弹窗文案不可以为空");
|
||||
return;
|
||||
}
|
||||
|
||||
CGFloat width = [UIScreen mainScreen].bounds.size.width - 40 * 2;
|
||||
CGFloat height = ([self messageSize:config.message width:width].height + 160);
|
||||
|
||||
// 最小 200, 最大 450
|
||||
if (height < kMixHeight) {
|
||||
height = kMixHeight;
|
||||
} else if (height > kMaxHeight) {
|
||||
height = kMaxHeight;
|
||||
}
|
||||
|
||||
TTAlertView *contentView = [[TTAlertView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
|
||||
contentView.config = config;
|
||||
contentView.cancelAction = cancelHandler;
|
||||
contentView.confirmAction = confirmHandler;
|
||||
contentView.isConfigBoard = isShowBorder;
|
||||
|
||||
if (!contentView.config.disableAutoDismissWhenClickButton) {
|
||||
// 设置弹窗按钮自动消除
|
||||
contentView.dismissAction = ^{
|
||||
[TTPopup dismiss];
|
||||
};
|
||||
}
|
||||
|
||||
[self popupView:contentView style:TTPopupStyleAlert config:config];
|
||||
}
|
||||
|
||||
#pragma mark Action Sheet
|
||||
+ (void)actionSheetWithItems:(NSArray<TTActionSheetConfig *> *)items {
|
||||
|
||||
[TTPopup actionSheetWithItems:items showCancelItem:YES cancelHandler:nil];
|
||||
}
|
||||
|
||||
+ (void)actionSheetWithItems:(NSArray<TTActionSheetConfig *> *)items
|
||||
showCancelItem:(BOOL)showCancelItem {
|
||||
|
||||
[TTPopup actionSheetWithItems:items showCancelItem:showCancelItem cancelHandler:nil];
|
||||
}
|
||||
|
||||
+ (void)actionSheetWithItems:(NSArray<TTActionSheetConfig *> *)items cancelHandler:(TTActionSheetClickAction)cancelHandler {
|
||||
|
||||
[TTPopup actionSheetWithItems:items showCancelItem:YES cancelHandler:cancelHandler];
|
||||
}
|
||||
|
||||
+ (void)actionSheetWithItems:(NSArray<TTActionSheetConfig *> *)items
|
||||
showCancelItem:(BOOL)showCancelItem
|
||||
cancelHandler:(TTActionSheetClickAction)cancelHandler {
|
||||
|
||||
CGFloat width = [UIScreen mainScreen].bounds.size.width - kActionSheetViewPadding * 2;
|
||||
CGFloat height = kActionSheetViewCellHeight * items.count + kActionSheetViewBottomPadding;
|
||||
|
||||
// 如果需要显示取消按钮则增加响应的高度
|
||||
if (showCancelItem) {
|
||||
// 按钮的高度和间距
|
||||
height += kActionSheetViewCancelViewHeight;
|
||||
}
|
||||
|
||||
if (@available(iOS 11.0, *)) {
|
||||
// 如果是 iPhone X 系列(刘海屏幕系列) 底部则需要添加 34 的高度
|
||||
height += [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom;
|
||||
}
|
||||
|
||||
CGRect rect = CGRectMake(0, 0, width, height);
|
||||
|
||||
TTActionSheetView *sheetView = [[TTActionSheetView alloc] initWithFrame:rect
|
||||
needCancel:showCancelItem
|
||||
items:items];
|
||||
sheetView.cancelAction = cancelHandler;
|
||||
|
||||
// 设置弹窗按钮自动消除
|
||||
sheetView.dismissAction = ^{
|
||||
[TTPopup dismiss];
|
||||
};
|
||||
|
||||
[self popupView:sheetView style:TTPopupStyleActionSheet];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Popup
|
||||
+ (void)popupView:(UIView *)customView
|
||||
style:(TTPopupStyle)style {
|
||||
|
||||
TTPopupService *service = [[TTPopupService alloc] init];
|
||||
service.style = style;
|
||||
service.contentView = customView;
|
||||
|
||||
[self popupWithConfig:service];
|
||||
}
|
||||
|
||||
+ (void)popupView:(UIView *)customView
|
||||
style:(TTPopupStyle)style
|
||||
config:(TTAlertConfig *)config {
|
||||
|
||||
TTPopupService *service = [[TTPopupService alloc] init];
|
||||
service.style = style;
|
||||
service.contentView = customView;
|
||||
service.shouldDismissOnBackgroundTouch = config.shouldDismissOnBackgroundTouch;
|
||||
service.maskBackgroundAlpha = config.maskBackgroundAlpha;
|
||||
[self popupWithConfig:service];
|
||||
}
|
||||
|
||||
|
||||
+ (void)popupWithConfig:(TTPopupService *)config {
|
||||
if (![config.contentView isKindOfClass:UIView.class]) {
|
||||
NSAssert(NO, @"TTPopup customView should inherit from UIView.");
|
||||
return;
|
||||
}
|
||||
[[TTPopupManagerService sharedInstance] addPopupService:config];
|
||||
}
|
||||
|
||||
#pragma mark Dismiss
|
||||
+ (void)dismiss {
|
||||
[[TTPopupManagerService sharedInstance] removePopupService];
|
||||
}
|
||||
|
||||
#pragma mark Query
|
||||
/**
|
||||
当前是否有显示弹窗
|
||||
*/
|
||||
+ (BOOL)hasShowPopup {
|
||||
return [TTPopupManagerService sharedInstance].currentPopupService != nil;
|
||||
}
|
||||
|
||||
#pragma mark - Privite
|
||||
+ (CGSize)messageSize:(NSString *)text width:(CGFloat)width {
|
||||
CGRect stringRect = [text boundingRectWithSize:CGSizeMake(width - 2 * 20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.f]} context:nil];
|
||||
return stringRect.size;
|
||||
}
|
||||
|
||||
@end
|
26
YuMi/CustomUI/TTPopup/View/TTActionSheetView.h
Normal file
26
YuMi/CustomUI/TTPopup/View/TTActionSheetView.h
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// TTActionSheetView.h
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lee on 2019/5/22.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TTPopupConstants.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class TTActionSheetConfig;
|
||||
|
||||
@interface TTActionSheetView : UIView
|
||||
|
||||
@property (nonatomic, copy) TTPopupCompletionHandler cancelAction;
|
||||
@property (nonatomic, copy) TTPopupCompletionHandler dismissAction;
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
needCancel:(BOOL)needCancel
|
||||
items:(NSArray<TTActionSheetConfig *> *)items;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
159
YuMi/CustomUI/TTPopup/View/TTActionSheetView.m
Normal file
159
YuMi/CustomUI/TTPopup/View/TTActionSheetView.m
Normal file
@@ -0,0 +1,159 @@
|
||||
//
|
||||
// TTActionSheetView.m
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lee on 2019/5/22.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TTActionSheetView.h"
|
||||
#import "TTActionSheetConfig.h"
|
||||
#import "DJDKMIMOMColor.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
|
||||
static CGFloat const kSheetViewCellHeight = 51.f;
|
||||
static CGFloat const kSheetViewCornerRadius = 14.f;
|
||||
static NSString *const kSheetViewCellConst = @"kSheetViewCellConst";
|
||||
|
||||
@interface TTActionSheetView ()<UITableViewDelegate, UITableViewDataSource>
|
||||
|
||||
/** sheetView 载体 */
|
||||
@property (nonatomic, strong) UITableView *tableView;
|
||||
/** 数据源 */
|
||||
@property (nonatomic, strong) NSArray<TTActionSheetConfig *> *items;
|
||||
/** 是否需要显示取消按钮 */
|
||||
@property (nonatomic, assign) BOOL needCancel;
|
||||
/** 取消按钮 */
|
||||
@property (nonatomic, strong) UIButton *cancelButton;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TTActionSheetView
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark lifeCycle
|
||||
- (instancetype)initWithFrame:(CGRect)frame needCancel:(BOOL)needCancel items:(NSArray<TTActionSheetConfig *> *)items {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
_items = items;
|
||||
_needCancel = needCancel;
|
||||
[self initViews];
|
||||
[self initConstraints];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initViews {
|
||||
[self addSubview:self.tableView];
|
||||
[self addSubview:self.cancelButton];
|
||||
}
|
||||
|
||||
- (void)initConstraints {
|
||||
|
||||
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.trailing.top.mas_equalTo(self);
|
||||
make.height.mas_equalTo(self.items.count * kSheetViewCellHeight);
|
||||
}];
|
||||
|
||||
if (_needCancel) {
|
||||
// 显示 cancel view
|
||||
self.cancelButton.hidden = NO;
|
||||
[self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.trailing.mas_equalTo(self);
|
||||
make.height.mas_equalTo(kSheetViewCellHeight);
|
||||
make.top.mas_equalTo(self.tableView.mas_bottom).offset(15);
|
||||
}];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
return self.items.count;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kSheetViewCellConst];
|
||||
cell.backgroundColor = UIColor.clearColor;
|
||||
cell.textLabel.textAlignment = NSTextAlignmentCenter;
|
||||
cell.textLabel.text = _items[indexPath.row].title;
|
||||
cell.textLabel.textColor = _items[indexPath.row].titleColor;
|
||||
|
||||
if ([_items[indexPath.row] displayMoliCoin]) {
|
||||
NSTextAttachment *coinAttachment = [[NSTextAttachment alloc] init];
|
||||
coinAttachment.image = kImage(@"moli_money_icon");
|
||||
coinAttachment.bounds = CGRectMake(0, -3.5, 20, 20);
|
||||
NSAttributedString *coinAttributedString = [NSAttributedString attributedStringWithAttachment:coinAttachment];
|
||||
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithAttributedString:coinAttributedString];
|
||||
NSAttributedString *titleAttributedString = [[NSAttributedString alloc] initWithString:_items[indexPath.row].title
|
||||
attributes:@{
|
||||
NSForegroundColorAttributeName: _items[indexPath.row].titleColor,
|
||||
NSFontAttributeName: cell.textLabel.font
|
||||
}];
|
||||
[string insertAttributedString:titleAttributedString atIndex:0];
|
||||
cell.textLabel.attributedText = string.copy;
|
||||
|
||||
UIImageView *questionMark = [[UIImageView alloc] initWithImage:kImage(@"question_mark")];
|
||||
[cell.contentView addSubview:questionMark];
|
||||
[questionMark mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.mas_equalTo(cell.textLabel);
|
||||
make.trailing.mas_equalTo(-20);
|
||||
make.size.mas_equalTo(CGSizeMake(22, 22));
|
||||
}];
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
|
||||
// 配置中的事件处理
|
||||
TTActionSheetConfig *config = _items[indexPath.row];
|
||||
!config.clickAction ?: config.clickAction();
|
||||
|
||||
!_dismissAction ?: _dismissAction();
|
||||
}
|
||||
|
||||
- (void)onClickCancelButtonAction:(UIButton *)cancelButton {
|
||||
!_cancelAction ?: _cancelAction();
|
||||
!_dismissAction ?: _dismissAction();
|
||||
}
|
||||
|
||||
- (UITableView *)tableView {
|
||||
if (!_tableView) {
|
||||
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
||||
_tableView.delegate = self;
|
||||
_tableView.dataSource = self;
|
||||
_tableView.separatorColor = [DJDKMIMOMColor actionSeparatorColor];
|
||||
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
|
||||
_tableView.rowHeight = kSheetViewCellHeight;
|
||||
_tableView.tableFooterView = [[UIView alloc] init];
|
||||
_tableView.backgroundColor = [UIColor whiteColor];
|
||||
_tableView.layer.cornerRadius = kSheetViewCornerRadius;
|
||||
_tableView.layer.masksToBounds = YES;
|
||||
_tableView.bounces = NO;
|
||||
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kSheetViewCellConst];
|
||||
}
|
||||
return _tableView;
|
||||
}
|
||||
|
||||
- (UIButton *)cancelButton {
|
||||
if (!_cancelButton) {
|
||||
_cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_cancelButton setTitle:YMLocalizedString(@"TTActionSheetView0") forState:UIControlStateNormal];
|
||||
[_cancelButton setBackgroundColor:UIColor.whiteColor];
|
||||
[_cancelButton setTitleColor:[DJDKMIMOMColor alertMessageColor] forState:UIControlStateNormal];
|
||||
[_cancelButton.titleLabel setFont:[UIFont systemFontOfSize:16]];
|
||||
_cancelButton.layer.cornerRadius = kSheetViewCornerRadius;
|
||||
_cancelButton.layer.masksToBounds = YES;
|
||||
[_cancelButton addTarget:self action:@selector(onClickCancelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
||||
_cancelButton.hidden = YES;
|
||||
}
|
||||
return _cancelButton;
|
||||
}
|
||||
|
||||
@end
|
25
YuMi/CustomUI/TTPopup/View/TTAlertView.h
Normal file
25
YuMi/CustomUI/TTPopup/View/TTAlertView.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// TTAlertView.h
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lee on 2019/5/20.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TTPopupConstants.h"
|
||||
|
||||
@class TTAlertConfig;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TTAlertView : UIView
|
||||
@property (nonatomic, strong) TTAlertConfig *config;// 配置
|
||||
@property (nonatomic, assign) BOOL isConfigBoard;// 是否配置边框
|
||||
@property (nonatomic, copy) TTPopupCompletionHandler cancelAction;
|
||||
@property (nonatomic, copy) TTPopupCompletionHandler confirmAction;
|
||||
@property (nonatomic, copy) TTPopupCompletionHandler dismissAction;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
255
YuMi/CustomUI/TTPopup/View/TTAlertView.m
Normal file
255
YuMi/CustomUI/TTPopup/View/TTAlertView.m
Normal file
@@ -0,0 +1,255 @@
|
||||
//
|
||||
// TTAlertView.m
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
// Created by lee on 2019/5/20.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TTAlertView.h"
|
||||
#import "TTAlertConfig.h"
|
||||
#import "DJDKMIMOMColor.h"
|
||||
#import <Masonry/Masonry.h>
|
||||
|
||||
static CGFloat const kMargin = 25.f;
|
||||
static CGFloat const kPadding = 20.f;
|
||||
static CGFloat const kBtnHeight = 38.f;
|
||||
|
||||
@interface TTAlertView ()
|
||||
|
||||
@property (nonatomic, strong) UILabel *titleLabel; // 标题
|
||||
@property (nonatomic, strong) UILabel *messageLabel; // 内容
|
||||
@property (nonatomic, strong) UIButton *cancelButton; // 取消按钮
|
||||
@property (nonatomic, strong) UIButton *confirmButton; // 确认按钮
|
||||
@property (nonatomic, strong) UIStackView *stackView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TTAlertView
|
||||
|
||||
#pragma mark - lifeCyle
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self initViews];
|
||||
[self initConstraints];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initViews {
|
||||
[self addSubview:self.titleLabel];
|
||||
[self addSubview:self.messageLabel];
|
||||
[self addSubview:self.stackView];
|
||||
[self.stackView addSubview:self.cancelButton];
|
||||
[self.stackView addSubview:self.confirmButton];
|
||||
}
|
||||
|
||||
- (void)initConstraints {
|
||||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self);
|
||||
make.top.mas_equalTo(kPadding);
|
||||
make.leading.trailing.mas_equalTo(self).inset(kPadding);
|
||||
}];
|
||||
|
||||
[self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(kMargin);
|
||||
make.leading.trailing.mas_equalTo(self).inset(kPadding);
|
||||
make.bottom.mas_equalTo(self).offset(-kBtnHeight * 2);
|
||||
}];
|
||||
|
||||
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(-kPadding);
|
||||
make.centerX.mas_equalTo(self);
|
||||
}];
|
||||
|
||||
[self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(kBtnHeight);
|
||||
make.width.mas_equalTo(self.mas_width).multipliedBy(0.4);
|
||||
}];
|
||||
|
||||
[self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(kBtnHeight);
|
||||
make.width.mas_equalTo(self.mas_width).multipliedBy(0.4);
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Button Events
|
||||
- (void)onClickConfirmButtonAction:(UIButton *)confirmButton {
|
||||
!_confirmAction ?: _confirmAction();
|
||||
!_dismissAction ?: _dismissAction();
|
||||
}
|
||||
|
||||
- (void)onClickCancelButtonAction:(UIButton *)cancelButton {
|
||||
!_cancelAction ?: _cancelAction();
|
||||
!_dismissAction ?: _dismissAction();
|
||||
}
|
||||
|
||||
#pragma mark - private method
|
||||
/**
|
||||
设置 messageLabel 需要显示的富文本效果
|
||||
@param config 弹窗配置
|
||||
@return 富文本内容
|
||||
*/
|
||||
- (NSMutableAttributedString *)messageAttributeString:(TTAlertConfig *)config {
|
||||
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:config.message];
|
||||
if (config.messageLineSpacing > 0) { // 行间距
|
||||
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
||||
paragraphStyle.lineSpacing = config.messageLineSpacing;
|
||||
paragraphStyle.alignment = config.messageTextAlignment;
|
||||
[attString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, config.message.length)];
|
||||
}
|
||||
|
||||
// 富文本显示效果
|
||||
[config.messageAttributedConfig enumerateObjectsUsingBlock:^(TTAlertMessageAttributedConfig * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
// 遍历数组,添加展示富文本效果
|
||||
if ([obj isKindOfClass:[TTAlertMessageAttributedConfig class]]) {
|
||||
if (obj.text && obj.text.length > 0) {
|
||||
NSRange range = [config.message rangeOfString:obj.text];
|
||||
// 如果外部指定了 range 。就不用查找出的 range
|
||||
if (obj.range.length != 0) {
|
||||
if (obj.range.location + obj.range.length > config.message.length) {
|
||||
NSAssert(NO, @"obj.range out of bounds");
|
||||
return;
|
||||
}
|
||||
range = obj.range;
|
||||
}
|
||||
if (obj.font) { // 字体
|
||||
[attString addAttribute:NSFontAttributeName value:obj.font range:range];
|
||||
}
|
||||
if (obj.color) { // 颜色
|
||||
[attString addAttribute:NSForegroundColorAttributeName value:obj.color range:range];
|
||||
}
|
||||
}
|
||||
}
|
||||
}];
|
||||
return attString;
|
||||
}
|
||||
|
||||
#pragma mark - getter && setter
|
||||
|
||||
- (void)setConfig:(TTAlertConfig *)config {
|
||||
_config = config;
|
||||
// cornerRadius
|
||||
if (config.cornerRadius > 0) {
|
||||
self.layer.cornerRadius = config.cornerRadius;
|
||||
self.layer.masksToBounds = YES;
|
||||
}
|
||||
//背景
|
||||
self.backgroundColor = config.backgroundColor;
|
||||
// title
|
||||
_titleLabel.text = config.title;
|
||||
_titleLabel.textColor = config.titleColor;
|
||||
_titleLabel.font = config.titleFont;
|
||||
|
||||
_cancelButton.hidden = config.actionStyle == TTAlertActionConfirmStyle;
|
||||
_confirmButton.hidden = config.actionStyle == TTAlertActionCancelStyle;
|
||||
|
||||
// cancel button
|
||||
[_cancelButton setTitle:config.cancelButtonConfig.title forState:UIControlStateNormal];
|
||||
[_cancelButton setTitleColor:config.cancelButtonConfig.titleColor forState:UIControlStateNormal];
|
||||
[_cancelButton.titleLabel setFont:config.cancelButtonConfig.font];
|
||||
[_cancelButton setBackgroundColor:config.cancelButtonConfig.backgroundColor];
|
||||
[_cancelButton setBackgroundImage:config.cancelButtonConfig.backgroundImage forState:UIControlStateNormal];
|
||||
if (config.cancelButtonConfig.cornerRadius > 0) {
|
||||
_cancelButton.layer.cornerRadius = config.cancelButtonConfig.cornerRadius;
|
||||
_cancelButton.layer.masksToBounds = YES;
|
||||
}
|
||||
|
||||
// confirm button
|
||||
[_confirmButton setTitle:config.confirmButtonConfig.title forState:UIControlStateNormal];
|
||||
[_confirmButton setTitleColor:config.confirmButtonConfig.titleColor forState:UIControlStateNormal];
|
||||
[_confirmButton.titleLabel setFont:config.confirmButtonConfig.font];
|
||||
[_confirmButton setBackgroundColor:config.confirmButtonConfig.backgroundColor];
|
||||
[_confirmButton setBackgroundImage:config.confirmButtonConfig.backgroundImage forState:UIControlStateNormal];
|
||||
if (config.confirmButtonConfig.cornerRadius > 0) {
|
||||
_confirmButton.layer.cornerRadius = config.confirmButtonConfig.cornerRadius;
|
||||
_confirmButton.layer.masksToBounds = YES;
|
||||
}
|
||||
|
||||
// message
|
||||
_messageLabel.font = config.messageFont;
|
||||
_messageLabel.textColor = config.messageColor;
|
||||
|
||||
if (config.messageAttributedConfig.count > 0) {
|
||||
_messageLabel.attributedText = [self messageAttributeString:config];
|
||||
_messageLabel.textAlignment = NSTextAlignmentCenter;
|
||||
} else if(config.messageAttributed.length > 0) {
|
||||
_messageLabel.attributedText = config.messageAttributed;
|
||||
_messageLabel.textAlignment = NSTextAlignmentCenter;
|
||||
} else {
|
||||
_messageLabel.text = config.message;
|
||||
_messageLabel.textAlignment = config.messageTextAlignment;
|
||||
}
|
||||
|
||||
_cancelButton.layer.borderColor = [DJDKMIMOMColor dividerColor].CGColor;
|
||||
_cancelButton.layer.borderWidth = 2.f;
|
||||
_confirmButton.layer.borderColor = [DJDKMIMOMColor dividerColor].CGColor;
|
||||
_confirmButton.layer.borderWidth = 2.f;
|
||||
}
|
||||
|
||||
- (void)setIsConfigBoard:(BOOL)isConfigBoard {
|
||||
_isConfigBoard = isConfigBoard;
|
||||
if (isConfigBoard) {
|
||||
//需要边框
|
||||
_cancelButton.layer.borderColor = [DJDKMIMOMColor dividerColor].CGColor;
|
||||
_cancelButton.layer.borderWidth = 2.f;
|
||||
_confirmButton.layer.borderColor = [DJDKMIMOMColor dividerColor].CGColor;
|
||||
_confirmButton.layer.borderWidth = 2.f;
|
||||
}else {
|
||||
//不需要边框
|
||||
_cancelButton.layer.borderColor = [DJDKMIMOMColor dividerColor].CGColor;
|
||||
_cancelButton.layer.borderWidth = 0;
|
||||
_confirmButton.layer.borderColor = [DJDKMIMOMColor dividerColor].CGColor;
|
||||
_confirmButton.layer.borderWidth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (UILabel *)titleLabel {
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [[UILabel alloc] init];
|
||||
_titleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_titleLabel.numberOfLines = 0;
|
||||
}
|
||||
return _titleLabel ;
|
||||
}
|
||||
|
||||
- (UILabel *)messageLabel {
|
||||
if (!_messageLabel) {
|
||||
_messageLabel = [[UILabel alloc] init];
|
||||
_messageLabel.numberOfLines = 0;
|
||||
_messageLabel.textAlignment = NSTextAlignmentCenter;
|
||||
_messageLabel.minimumScaleFactor = 0.7;
|
||||
_messageLabel.adjustsFontSizeToFitWidth = YES;
|
||||
}
|
||||
return _messageLabel;
|
||||
}
|
||||
|
||||
- (UIButton *)cancelButton {
|
||||
if (!_cancelButton) {
|
||||
_cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_cancelButton addTarget:self action:@selector(onClickCancelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _cancelButton;
|
||||
}
|
||||
|
||||
- (UIButton *)confirmButton {
|
||||
if (!_confirmButton) {
|
||||
_confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_confirmButton addTarget:self action:@selector(onClickConfirmButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _confirmButton;
|
||||
}
|
||||
|
||||
- (UIStackView *)stackView {
|
||||
if (!_stackView) {
|
||||
_stackView = [[UIStackView alloc] initWithArrangedSubviews:@[self.cancelButton, self.confirmButton]];
|
||||
_stackView.distribution = UIStackViewDistributionFillEqually;
|
||||
_stackView.alignment = UIStackViewAlignmentCenter;
|
||||
_stackView.spacing = 16;
|
||||
}
|
||||
return _stackView;
|
||||
}
|
||||
|
||||
@end
|
20
YuMi/CustomUI/TTPopup/View/TTNewAlertView.h
Normal file
20
YuMi/CustomUI/TTPopup/View/TTNewAlertView.h
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// TTNewAlertView.h
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by duoban on 2023/1/9.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
||||
|
||||
|
||||
@interface TTNewAlertView : UIView
|
||||
@property (nonatomic,copy) NSString *message;
|
||||
@property (nonatomic, copy) TTPopupCompletionHandler confirmHandle;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
118
YuMi/CustomUI/TTPopup/View/TTNewAlertView.m
Normal file
118
YuMi/CustomUI/TTPopup/View/TTNewAlertView.m
Normal file
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// TTNewAlertView.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by duoban on 2023/1/9.
|
||||
//
|
||||
|
||||
#import "TTNewAlertView.h"
|
||||
@interface TTNewAlertView()
|
||||
@property (nonatomic,strong) UIView *bgView;
|
||||
@property (nonatomic,strong) UILabel *messageView;
|
||||
@property (nonatomic,strong) UIButton *confirmBtn;
|
||||
@property (nonatomic,strong) UIButton *cancelBtn;
|
||||
@end
|
||||
@implementation TTNewAlertView
|
||||
|
||||
-(instancetype)initWithFrame:(CGRect)frame{
|
||||
self = [super initWithFrame:frame];
|
||||
if(self){
|
||||
[self initSubViews];
|
||||
[self initSubViewConstraints];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Private Method
|
||||
- (void)initSubViews {
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
[self addSubview:self.bgView];
|
||||
[self.bgView addSubview:self.messageView];
|
||||
[self.bgView addSubview:self.confirmBtn];
|
||||
[self.bgView addSubview:self.cancelBtn];
|
||||
}
|
||||
- (void)initSubViewConstraints {
|
||||
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(kGetScaleWidth(310));
|
||||
make.height.mas_equalTo(kGetScaleWidth(149));
|
||||
make.center.equalTo(self);
|
||||
}];
|
||||
|
||||
|
||||
[self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.height.mas_equalTo(kGetScaleWidth(110));
|
||||
make.height.mas_equalTo(kGetScaleWidth(37));
|
||||
make.leading.mas_equalTo(kGetScaleWidth(31));
|
||||
make.bottom.mas_equalTo(-kGetScaleWidth(31));
|
||||
}];
|
||||
|
||||
[self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.height.centerY.equalTo(self.confirmBtn);
|
||||
make.trailing.mas_equalTo(-kGetScaleWidth(31));
|
||||
}];
|
||||
|
||||
[self.messageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(kGetScaleWidth(25));
|
||||
make.centerX.equalTo(self);
|
||||
make.leading.trailing.equalTo(self).inset(kGetScaleWidth(10));
|
||||
}];
|
||||
|
||||
|
||||
|
||||
}
|
||||
-(void)setMessage:(NSString *)message{
|
||||
_message = message;
|
||||
_messageView.text = message;
|
||||
}
|
||||
-(void)confirmAction{
|
||||
[TTPopup dismiss];
|
||||
if(self.confirmHandle){
|
||||
self.confirmHandle();
|
||||
}
|
||||
}
|
||||
-(void)cancelAction{
|
||||
[TTPopup dismiss];
|
||||
}
|
||||
|
||||
#pragma mark -懒加载
|
||||
|
||||
- (UIView *)bgView{
|
||||
if (!_bgView){
|
||||
_bgView = [UIView new];
|
||||
_bgView.backgroundColor = [UIColor whiteColor];
|
||||
[_bgView setCornerWithLeftTopCorner:kGetScaleWidth(12) rightTopCorner:kGetScaleWidth(12) bottomLeftCorner:kGetScaleWidth(12) bottomRightCorner:kGetScaleWidth(12) size:CGSizeMake(kGetScaleWidth(310), kGetScaleWidth(149))];
|
||||
}
|
||||
return _bgView;
|
||||
}
|
||||
- (UILabel *)messageView{
|
||||
if (!_messageView){
|
||||
_messageView = [UILabel labelInitWithText:@"" font:kFontRegular(15) textColor:[DJDKMIMOMColor inputTextColor]];
|
||||
_messageView.textAlignment = NSTextAlignmentCenter;
|
||||
_messageView.numberOfLines = 0;
|
||||
}
|
||||
return _messageView;
|
||||
}
|
||||
-(UIButton *)confirmBtn{
|
||||
if (!_confirmBtn){
|
||||
_confirmBtn = [UIButton new];
|
||||
[_confirmBtn setTitle:YMLocalizedString(@"TTAlertConfig0") forState:UIControlStateNormal];
|
||||
_confirmBtn.backgroundColor = UIColorFromRGB(0xE6E6F0);
|
||||
_confirmBtn.layer.cornerRadius = kGetScaleWidth(37)/2;
|
||||
_confirmBtn.layer.masksToBounds = YES;
|
||||
[_confirmBtn addTarget:self action:@selector(confirmAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _confirmBtn;
|
||||
}
|
||||
-(UIButton *)cancelBtn{
|
||||
if (!_cancelBtn){
|
||||
_cancelBtn = [UIButton new];
|
||||
[_cancelBtn setTitle:YMLocalizedString(@"XPShareView7") forState:UIControlStateNormal];
|
||||
UIImage *image = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor],[DJDKMIMOMColor confirmButtonGradientMiddleColor],[DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(110), kGetScaleWidth(37))];
|
||||
_cancelBtn.backgroundColor = [UIColor colorWithPatternImage:image];
|
||||
_cancelBtn.layer.cornerRadius = kGetScaleWidth(37)/2;
|
||||
_cancelBtn.layer.masksToBounds = YES;
|
||||
[_cancelBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _cancelBtn;
|
||||
}
|
||||
@end
|
Reference in New Issue
Block a user