-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathYoAlert.m
97 lines (83 loc) · 2.33 KB
/
YoAlert.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
//
// YoAlert.m
// Yo
//
// Created by Peter Reveles on 2/3/15.
//
//
#import "YoAlert.h"
#define MAX_ALLOWED_ACTIONS 4
@interface YoAlert ()
@property (strong, nonatomic) NSString *title;
@property (strong, nonatomic) NSAttributedString *descriptionText;
@property (strong, nonatomic) UIImage *image;
@property (strong, nonatomic) NSMutableArray *actions;
@end
@implementation YoAlert
#pragma mark - Lazy Loading
- (NSMutableArray *)actions{
if (!_actions) {
_actions = [[NSMutableArray alloc] initWithCapacity:MAX_ALLOWED_ACTIONS];
}
return _actions;
}
#pragma mark - Life
- (instancetype)initWithTitle:(NSString *)title
attributedDesciption:(NSAttributedString *)attributedDesciption
{
self = [super init];
if (self) {
_title = title;
_descriptionText = attributedDesciption;
}
return self;
}
- (instancetype)initWithTitle:(NSString *)title
desciption:(NSString *)description
{
if (description == nil) {
description = title;
title = @"Yo";
}
NSAttributedString *attributedDescription = [[NSAttributedString alloc]
initWithString:description
attributes:nil];
self = [self initWithTitle:title attributedDesciption:attributedDescription];
if (self) {
// nop
}
return self;
}
- (instancetype)initWithTitle:(NSString *)title
image:(UIImage *)image
desciption:(NSString *)description
{
self = [self initWithTitle:title desciption:description];
if (self) {
_image = image;
}
return self;
}
- (instancetype)initWithTitle:(NSString *)title
image:(UIImage *)image
attributedDesciption:(NSAttributedString *)attributedDesciption
{
self = [self initWithTitle:title attributedDesciption:attributedDesciption];
if (self) {
_image = image;
}
return self;
}
- (void)addAction:(YoAlertAction *)action
{
if (action && action.title) {
if ([self.actions count] < MAX_ALLOWED_ACTIONS) {
[self.actions addObject:action];
}
else
DDLogWarn(@"Exceed MAX Allowed number of actions per alert view");
}
else
DDLogWarn(@"Action not added to share sheet.");
}
@end