keep edit
This commit is contained in:
@@ -1,26 +1,24 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
|
||||
// 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
|
||||
|
26
YuMi/CustomUI/TTPopup/View/TTActionSheetView.h.backup
Normal file
26
YuMi/CustomUI/TTPopup/View/TTActionSheetView.h.backup
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
|
@@ -1,10 +1,8 @@
|
||||
//
|
||||
// TTActionSheetView.m
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
|
||||
|
||||
// Created by lee on 2019/5/22.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#import "TTActionSheetView.h"
|
||||
#import "TTActionSheetConfig.h"
|
||||
@@ -17,13 +15,13 @@ 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
|
||||
@@ -56,7 +54,7 @@ static NSString *const kSheetViewCellConst = @"kSheetViewCellConst";
|
||||
}];
|
||||
|
||||
if (_needCancel) {
|
||||
// 显示 cancel view
|
||||
|
||||
self.cancelButton.hidden = NO;
|
||||
[self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.leading.trailing.mas_equalTo(self);
|
||||
@@ -111,7 +109,7 @@ static NSString *const kSheetViewCellConst = @"kSheetViewCellConst";
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
|
||||
// 配置中的事件处理
|
||||
|
||||
TTActionSheetConfig *config = _items[indexPath.row];
|
||||
!config.clickAction ?: config.clickAction();
|
||||
|
||||
|
159
YuMi/CustomUI/TTPopup/View/TTActionSheetView.m.backup
Normal file
159
YuMi/CustomUI/TTPopup/View/TTActionSheetView.m.backup
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
|
@@ -1,25 +1,23 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
|
||||
// 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
|
||||
|
25
YuMi/CustomUI/TTPopup/View/TTAlertView.h.backup
Normal file
25
YuMi/CustomUI/TTPopup/View/TTAlertView.h.backup
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
|
@@ -1,10 +1,8 @@
|
||||
//
|
||||
// TTAlertView.m
|
||||
// YM_TTChatViewKit
|
||||
//
|
||||
|
||||
|
||||
// Created by lee on 2019/5/20.
|
||||
// Copyright © 2023 YUMI. All rights reserved.
|
||||
//
|
||||
|
||||
|
||||
#import "TTAlertView.h"
|
||||
#import "TTAlertConfig.h"
|
||||
@@ -17,10 +15,10 @@ 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) UILabel *titleLabel;
|
||||
@property (nonatomic, strong) UILabel *messageLabel;
|
||||
@property (nonatomic, strong) UIButton *cancelButton;
|
||||
@property (nonatomic, strong) UIButton *confirmButton;
|
||||
@property (nonatomic, strong) UIStackView *stackView;
|
||||
|
||||
@end
|
||||
@@ -86,27 +84,24 @@ static CGFloat const kBtnHeight = 38.f;
|
||||
}
|
||||
|
||||
#pragma mark - private method
|
||||
/**
|
||||
设置 messageLabel 需要显示的富文本效果
|
||||
@param config 弹窗配置
|
||||
@return 富文本内容
|
||||
*/
|
||||
|
||||
|
||||
- (NSMutableAttributedString *)messageAttributeString:(TTAlertConfig *)config {
|
||||
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:config.message];
|
||||
if (config.messageLineSpacing > 0) { // 行间距
|
||||
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");
|
||||
@@ -114,10 +109,10 @@ static CGFloat const kBtnHeight = 38.f;
|
||||
}
|
||||
range = obj.range;
|
||||
}
|
||||
if (obj.font) { // 字体
|
||||
if (obj.font) {
|
||||
[attString addAttribute:NSFontAttributeName value:obj.font range:range];
|
||||
}
|
||||
if (obj.color) { // 颜色
|
||||
if (obj.color) {
|
||||
[attString addAttribute:NSForegroundColorAttributeName value:obj.color range:range];
|
||||
}
|
||||
}
|
||||
@@ -130,14 +125,14 @@ static CGFloat const kBtnHeight = 38.f;
|
||||
|
||||
- (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;
|
||||
@@ -145,7 +140,7 @@ static CGFloat const kBtnHeight = 38.f;
|
||||
_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];
|
||||
@@ -156,7 +151,7 @@ static CGFloat const kBtnHeight = 38.f;
|
||||
_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];
|
||||
@@ -167,7 +162,7 @@ static CGFloat const kBtnHeight = 38.f;
|
||||
_confirmButton.layer.masksToBounds = YES;
|
||||
}
|
||||
|
||||
// message
|
||||
|
||||
_messageLabel.font = config.messageFont;
|
||||
_messageLabel.textColor = config.messageColor;
|
||||
|
||||
@@ -191,13 +186,13 @@ static CGFloat const kBtnHeight = 38.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;
|
||||
|
255
YuMi/CustomUI/TTPopup/View/TTAlertView.m.backup
Normal file
255
YuMi/CustomUI/TTPopup/View/TTAlertView.m.backup
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
|
@@ -1,17 +1,13 @@
|
||||
//
|
||||
// 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;
|
||||
|
20
YuMi/CustomUI/TTPopup/View/TTNewAlertView.h.backup
Normal file
20
YuMi/CustomUI/TTPopup/View/TTNewAlertView.h.backup
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
|
@@ -1,9 +1,7 @@
|
||||
//
|
||||
// TTNewAlertView.m
|
||||
// xplan-ios
|
||||
//
|
||||
|
||||
|
||||
// Created by duoban on 2023/1/9.
|
||||
//
|
||||
|
||||
|
||||
#import "TTNewAlertView.h"
|
||||
@interface TTNewAlertView()
|
||||
@@ -58,7 +56,6 @@
|
||||
}];
|
||||
|
||||
|
||||
|
||||
}
|
||||
-(void)setMessage:(NSString *)message{
|
||||
_message = message;
|
||||
@@ -86,7 +83,7 @@
|
||||
}
|
||||
- (UILabel *)messageView{
|
||||
if (!_messageView){
|
||||
_messageView = [UILabel labelInitWithText:@"" font:kFontRegular(15) textColor:[DJDKMIMOMColor inputTextColor]];
|
||||
_messageView = [[UILabel alloc] init];
|
||||
_messageView.textAlignment = NSTextAlignmentCenter;
|
||||
_messageView.numberOfLines = 0;
|
||||
}
|
||||
|
118
YuMi/CustomUI/TTPopup/View/TTNewAlertView.m.backup
Normal file
118
YuMi/CustomUI/TTPopup/View/TTNewAlertView.m.backup
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