AlertHandler.m
5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// AlertHandler.m
// mkh_ios
//
// Created by 钱鋆 on 15/6/30.
// Copyright (c) 2015年 mkh.cn. All rights reserved.
//
#import "AlertHandler.h"
#import "MBProgressHUD.h"
@implementation AlertHandler
#pragma mark 创建单例
/**
* @author qianjun
*
* @brief 创建单例
*
* @return self
*/
+ (instancetype)sharedInstance {
static id sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
#pragma mark -ios默认的alert
-(void)showAlert_default_title:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle tag:(NSInteger)tag
{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:title
message:message delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:nil];
alertView.tag = tag;
alertView.opaque = YES;
[alertView show];
}
- (void)f_showAlert_default_title:(NSString *)title message:(NSString *)message confirmHandler:(void (^)(UIAlertAction *action))confirmHandler confirmTitle:(NSString *)confirmTitle target:(UIViewController *)target {
UIAlertController *_alertC_temp = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *_alertAct_confirm = [UIAlertAction actionWithTitle:confirmTitle style:UIAlertActionStyleCancel handler:confirmHandler];
[_alertC_temp addAction:_alertAct_confirm];
[target presentViewController:_alertC_temp animated:YES completion:nil];
}
- (void)f_showAlert_default_title:(NSString *)title message:(NSString *)message confirmHandler:(void (^)(UIAlertAction *action))confirmHandler confirmTitle:(NSString *)confirmTitle cancelHandler:(void (^)(UIAlertAction *action))cancelHandler cancelTitle:(NSString *)cancelTitle target:(UIViewController *)target {
UIAlertController *_alertC_temp = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *_alertAct_confirm = [UIAlertAction actionWithTitle:confirmTitle style:UIAlertActionStyleDefault handler:confirmHandler];
UIAlertAction *_alertAct_cancel = [UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:cancelHandler];
[_alertC_temp addAction:_alertAct_confirm];
[_alertC_temp addAction:_alertAct_cancel];
[target presentViewController:_alertC_temp animated:YES completion:nil];
}
#pragma mark -ios默认的confirm
-(void)showConfirm_default_title:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitle:(NSString *)otherButtonTitle tag:(NSInteger)tag
{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:title
message:message
delegate:delegate
cancelButtonTitle:cancelButtonTitle
otherButtonTitles:otherButtonTitle,nil];
alertView.opaque = YES;
alertView.tag = tag;
[alertView show];
}
#pragma mark - 定义类似于toast显示效果的HUD(每次临时生成,效果结束后立即remove)
-(void)showToastHUD:(UIView *)addView message:(NSString *)message sleepTime:(int)sleepTime
{
MBProgressHUD *hud_toast = [[MBProgressHUD alloc]initWithView:addView];
[hud_toast setDetailsLabelFont:FONT_S_18];
// 显示遮罩
//hud_toast.dimBackground = YES;
// 用detaillable,可以支持超长文字显示
hud_toast.detailsLabelText = message;
hud_toast.color = COLOR_S_LIGHTGRAY;
hud_toast.mode = MBProgressHUDModeText;
//[hud_toast setAlpha:1.0f];
hud_toast.opaque = YES;
[addView addSubview:hud_toast];
[hud_toast show:YES];
//指定距离中心点的X轴和Y轴的偏移量,如果不指定则在屏幕中间显示
//hud_toast.yOffset = yOffset;
//hud_toast.xOffset = xOffset;
[hud_toast showAnimated:YES whileExecutingBlock:^{
sleep(sleepTime);
} completionBlock:^{
[hud_toast removeFromSuperview];
}];
}
#pragma mark - 自定义画面(每次临时生成,效果结束后立即remove)
-(void)showCustomHUD:(UIView *)addView Image:(NSString *)image message:(NSString *)message sleepTime:(int)sleepTime
{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:addView animated:YES];
hud.mode = MBProgressHUDModeCustomView;
// UIImageView *imgV = [[UIImageView alloc] initWithImage:[UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e8c3", 40, COLOR_C_mainColor)]];
//
// hud.customView = imgV;
hud.square = YES;
hud.labelText = message;
[hud hide:YES afterDelay:sleepTime];
}
-(void)showDataSTempView:(UIView *)view sleepTime:(int)sleepTime
{
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
hud.mode = MBProgressHUDModeCustomView;
[hud hide:YES afterDelay:sleepTime];
}
@end