cdts/xdts-ios 3/TreeHole/Code/Utility/MTAlertView/MTAlertView.h
2023-07-27 09:20:00 +08:00

123 lines
4.8 KiB
Objective-C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// MTAlertView.h
// Meet
//
// Created by ko1o on 2018/9/17.
// Copyright © 2018年 ko1o. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "zhPopupController.h"
#ifndef MTAlertFixSize
#define MTAlertFixSize FIX_SIZE
#endif
#define kMTAlertContentSizeDefaultWidth MTAlertFixSize(280)
#define MTNO_DISMISS_TAG 123
#define MTWILL_DISMISS_TAG 20220814
@class MTAlertButton, MTAlertView;
typedef void(^MTAlertButtonHandler)(MTAlertButton *button);
typedef NS_ENUM(NSUInteger, MTAlertButtonType) {
MTAlertButtonTypeDefault, // 白色背景 黑色字体
MTAlertButtonTypeDefaultTheme, // 白色背景 主题色字体
MTAlertButtonTypeDefaultDestructive, // 白色背景 警告色字体
MTAlertButtonTypeNormal, // 主题色背景 白色字体
MTAlertButtonTypeCancel, // 白色 黑色字体 灰色边框
MTAlertButtonTypeDestructive, // 警告色背景 白色字体
};
@interface MTAlertButton : UIButton
+ (instancetype)buttonWithType:(UIButtonType)buttonType NS_UNAVAILABLE;
+ (instancetype)buttonWithType:(MTAlertButtonType)type title:(NSString *)title handler:(MTAlertButtonHandler)handler;
@property (nonatomic, assign) UIColor *lineColor; // 线条颜色
@property (nonatomic, assign) CGFloat lineWidth; // 线宽
@property (nonatomic, assign) UIEdgeInsets edgeInsets; //边缘留白 top -> 间距 / bottom -> 最底部留白(根据不同情况调整不同间距)
@end
static NSString *const kMTAlertViewCancelTitle = @"取消";
static NSString *const kMTAlertViewOtherTitle = @"确定";
static NSString *const kMTAlertViewDeleteTitle = @"删除";
@interface MTAlertViewConfig : NSObject
// 针对引导弹窗底部“X按钮”
@property (nonatomic, assign) BOOL shouldBottomCancelButton;
@property (nonatomic, copy) void (^bottomCancelButtonHandler)(MTAlertView *alertView);
// alertView一直存在
@property (nonatomic, assign) BOOL notDismissForever;
/// 弹窗图片 (UIImage or NSString)
/// icon有值 则使用icon布局: icon + title + message + cancel + other
@property (nonatomic, strong) id icon;
/// 弹窗标题(默认布局title + message + cancel + other)
@property (nonatomic, copy) NSString *title;
/// 弹窗内容
@property (nonatomic, copy) NSString *message;
/// 取消操作 标题&回调
@property (nonatomic, copy) NSString *cancelTitle;
@property (nonatomic, copy) MTAlertButtonHandler cancelHandler;
/// 其他操作 标题&回调
/// set otherDestructiveTitle equal to otherTitle = otherTitle && otherButtonType = MTAlertButtonTypeDestructive
@property (nonatomic, copy) NSString *otherDestructiveTitle;
/// set otherDestructiveTitle equal to otherTitle = otherTitle && otherButtonType = MTAlertButtonTypeDefaultDestructive
@property (nonatomic, copy) NSString *otherDefaultDestructiveTitle;
@property (nonatomic, copy) NSString *otherTitle;
@property (nonatomic, assign) MTAlertButtonType otherButtonType;
@property (nonatomic, copy) MTAlertButtonHandler otherHandler;
/// custom view 可传入自定义view
/// customView有值 则使用cutsom布局: custom view + cancel + other
@property (nonatomic, strong) UIView *customView;
@property (nonatomic, assign) BOOL onlyCustomView;
/// alert 使用popupController 完成show&dismiss
@property (nonatomic, strong) zhPopupController *popupController;
@end
/// 初始化配置使用该block
typedef void(^MTAlertViewSetupBlock)(MTAlertViewConfig *config);
/// 完成初始化且创建完所以组件后调用该block
typedef void(^MTAlertViewDidLayoutSubviewsBlock)(UILabel *titleLabel, UILabel *messageLabel, UIImageView *iconImageView, UIView *alertButtonContentView, UIButton *bottomCancelButton, UIView *customView, UIView *contentView, MTAlertView *alertView);
@interface MTAlertView : UIView
@property (nonatomic, strong, readonly) UILabel *messageLabel;
/// 根据配置创建AlertView
+ (instancetype)alertViewWithSetupBlock:(MTAlertViewSetupBlock)setupBlock;
- (instancetype)initWithSetupBlock:(MTAlertViewSetupBlock)setupBlock;
+ (MTAlertView *)showWithSetupBlcok:(MTAlertViewSetupBlock)setupBlock;
@property (nonatomic, copy) MTAlertViewDidLayoutSubviewsBlock didLayoutSubviewBlock;
@property (nonatomic, strong) void(^didDismiss)(MTAlertView *alertView);
@property (nonatomic, strong, readonly) MTAlertViewConfig *config;
// - (NSTimeInterval)
- (MTAlertView *)show;
- (MTAlertView *)showInView:(UIView *)view;
- (MTAlertView *)dismiss;
- (void)addAction:(NSString *)actionTitle type:(MTAlertButtonType)type actionHandler:(MTAlertButtonHandler)actionHandler;
+ (BOOL)hasAlertViewShowing;
@property (nonatomic, strong) UITextField *textField;
/// 显示自定义AlertView
+ (MTAlertView *)showAlertWithCustomView:(UIView *)actionView;
/// 显示自定义actonView
+ (zhPopupController *)showActionSheetWithCustomView:(UIView *)actionView;
@end