-
Notifications
You must be signed in to change notification settings - Fork 0
/
Alert.m
executable file
·118 lines (95 loc) · 3.27 KB
/
Alert.m
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
/*
File: URLCacheAlert.m
Abstract: Utility functions for the URLCache sample.
Version: 1.0
*/
#import "Alert.h"
#import "QuartzCore/CALayer.h"
@implementation UIAlertView (shortcuts)
+ (UIAlertView*) alertWithError:(NSError *)error
{
NSString *message = [NSString stringWithFormat:@"%@",[error localizedDescription]];
#ifdef _DEBUG
// LogError(@"Error: %@", [error localizedDescription]);
NSArray* detailedErrors = [error userInfo][@"NSDetailedErrors"];
if(detailedErrors && [detailedErrors count] > 0) {
for(NSError* detailedError in detailedErrors) {
// LogError(@"DetailedError: %@", [detailedError userInfo]);
}
} else {
// LogError(@"%@", error );
}
#endif
if ([[error domain] isEqualToString:NSURLErrorDomain]) {
return [UIAlertView alertWithTitle:@"Network Error" andMessage:message];
}
return [UIAlertView alertWithMessage:message];
}
+ (UIAlertView*) alertWithMessage:(NSString *)message {
/* open an alert with an OK button */
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:message
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK","Alert Button")
otherButtonTitles: nil];
[alert show];
// [alert release];
return alert;
}
+ (UIAlertView*) alertWithTitle:(NSString *) title andMessage:(NSString *)message {
/* open an alert with an OK button */
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK","Alert Button")
otherButtonTitles: nil];
[alert show];
// [alert release];
return alert;
}
+ (UIAlertView*) alertWithMessage:(NSString *)message title:(NSString *) title andDelegate:(id) delegate {
/* open an alert with OK and Cancel buttons */
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:delegate
cancelButtonTitle:NSLocalizedString(@"Cancel","Alert button")
otherButtonTitles: NSLocalizedString(@"OK","Alert button"), nil];
[alert show];
// [alert release];
return alert;
}
+ (UIAlertView*) alertWithMessage:(NSString *)message
title:(NSString *) title
okButton:(NSString *) ok
cancelButton:(NSString*)cancel
delegate:(id) delegate {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:delegate
cancelButtonTitle:cancel
otherButtonTitles: ok, nil];
[alert show];
// [alert release];
return alert;
}
- (UIAlertView*) customizeWithTitleColor:(UIColor*)tcolor messageColor:(UIColor*)mcolor image:(UIImage*)theImage {
if (tcolor) {
UILabel *theTitle = [self valueForKey:@"_titleLabel"];
[theTitle setTextColor:tcolor];
}
if (mcolor) {
UILabel *theBody = [self valueForKey:@"_bodyTextLabel"];
[theBody setTextColor:mcolor];
}
if (theImage) {
theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
CGSize theSize = [self frame].size;
UIGraphicsBeginImageContext(theSize);
[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];
theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.layer.contents = (id)[theImage CGImage];
}
return self;
}
@end