-
Notifications
You must be signed in to change notification settings - Fork 707
Expand file tree
/
Copy pathTSDemoViewController.m
More file actions
179 lines (154 loc) · 8.2 KB
/
TSDemoViewController.m
File metadata and controls
179 lines (154 loc) · 8.2 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//
// TSSecondViewController.m
// Example
//
// Created by Felix Krause on 13.04.13.
// Copyright (c) 2013 Felix Krause. All rights reserved.
//
#import "TSDemoViewController.h"
#import "TSMessage.h"
#import "TSMessageView.h"
@implementation TSDemoViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[TSMessage setDefaultViewController:self];
self.wantsFullScreenLayout = YES;
[self.navigationController.navigationBar setTranslucent:YES];
}
- (IBAction)didTapError:(id)sender
{
[TSMessage showNotificationWithTitle:NSLocalizedString(@"Something failed", nil)
subtitle:NSLocalizedString(@"The internet connection seems to be down. Please check that!", nil)
type:TSMessageNotificationTypeError];
}
- (IBAction)didTapWarning:(id)sender
{
[TSMessage showNotificationWithTitle:NSLocalizedString(@"Some random warning", nil)
subtitle:NSLocalizedString(@"Look out! Something is happening there!", nil)
type:TSMessageNotificationTypeWarning];
}
- (IBAction)didTapMessage:(id)sender
{
[TSMessage showNotificationWithTitle:NSLocalizedString(@"Tell the user something", nil)
subtitle:NSLocalizedString(@"This is some neutral notification!", nil)
type:TSMessageNotificationTypeMessage];
}
- (IBAction)didTapSuccess:(id)sender
{
[TSMessage showNotificationWithTitle:NSLocalizedString(@"Success", nil)
subtitle:NSLocalizedString(@"Some task was successfully completed!", nil)
type:TSMessageNotificationTypeSuccess];
}
- (IBAction)didTapButton:(id)sender
{
[TSMessage showNotificationInViewController:self
title:NSLocalizedString(@"New version available", nil)
subtitle:NSLocalizedString(@"Please update our app. We would be very thankful", nil)
image:nil
type:TSMessageNotificationTypeMessage
duration:TSMessageNotificationDurationAutomatic
callback:nil
buttonTitle:NSLocalizedString(@"Update", nil)
buttonCallback:^{
[TSMessage showNotificationWithTitle:NSLocalizedString(@"Thanks for updating", nil)
type:TSMessageNotificationTypeSuccess];
}
atPosition:TSMessageNotificationPositionTop
canBeDismissedByUser:YES
textAlign:NSTextAlignmentCenter];
}
- (IBAction)didTapToggleNavigationBar:(id)sender {
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBarHidden animated:YES];
}
- (IBAction)didTapToggleNavigationBarAlpha:(id)sender {
CGFloat alpha = self.navigationController.navigationBar.alpha;
self.navigationController.navigationBar.alpha = (alpha==1.f)?0.5:1;
}
- (IBAction)didTapToggleWantsFullscreen:(id)sender {
self.wantsFullScreenLayout = !self.wantsFullScreenLayout;
[self.navigationController.navigationBar setTranslucent:!self.navigationController.navigationBar.isTranslucent];
}
- (IBAction)didTapCustomImage:(id)sender
{
[TSMessage showNotificationInViewController:self
title:NSLocalizedString(@"Custom image", nil)
subtitle:NSLocalizedString(@"This uses an image you can define", nil)
image:[UIImage imageNamed:@"NotificationButtonBackground.png"]
type:TSMessageNotificationTypeMessage
duration:TSMessageNotificationDurationAutomatic
callback:nil
buttonTitle:nil
buttonCallback:nil
atPosition:TSMessageNotificationPositionTop
canBeDismissedByUser:YES
textAlign:NSTextAlignmentCenter];
}
- (IBAction)didTapDismissCurrentMessage:(id)sender
{
[TSMessage dismissActiveNotification];
}
- (IBAction)didTapEndless:(id)sender
{
[TSMessage showNotificationInViewController:self
title:NSLocalizedString(@"Endless", nil)
subtitle:NSLocalizedString(@"This message can not be dismissed and will not be hidden automatically. Tap the 'Dismiss' button to dismiss the currently shown message", nil)
image:nil
type:TSMessageNotificationTypeSuccess
duration:TSMessageNotificationDurationEndless
callback:nil
buttonTitle:nil
buttonCallback:nil
atPosition:TSMessageNotificationPositionTop
canBeDismissedByUser:NO
textAlign:NSTextAlignmentCenter];
}
- (IBAction)didTapLong:(id)sender
{
[TSMessage showNotificationInViewController:self
title:NSLocalizedString(@"Long", nil)
subtitle:NSLocalizedString(@"This message is displayed 10 seconds instead of the calculated value", nil)
image:nil
type:TSMessageNotificationTypeWarning
duration:10.0
callback:nil
buttonTitle:nil
buttonCallback:nil
atPosition:TSMessageNotificationPositionTop
canBeDismissedByUser:YES
textAlign:NSTextAlignmentCenter];
}
- (IBAction)didTapBottom:(id)sender
{
[TSMessage showNotificationInViewController:self
title:NSLocalizedString(@"Hu!", nil)
subtitle:NSLocalizedString(@"I'm down here :)", nil)
image:nil
type:TSMessageNotificationTypeSuccess
duration:TSMessageNotificationDurationAutomatic
callback:nil
buttonTitle:nil
buttonCallback:nil
atPosition:TSMessageNotificationPositionBottom
canBeDismissedByUser:YES
textAlign:NSTextAlignmentCenter];
}
- (IBAction)didTapText:(id)sender
{
[TSMessage showNotificationWithTitle:NSLocalizedString(@"With 'Text' I meant a long text, so here it is", nil)
subtitle:NSLocalizedString(@"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus", nil)
type:TSMessageNotificationTypeWarning];
}
- (IBAction)didTapCustomDesign:(id)sender
{
// this is an example on how to apply a custom design
[TSMessage addCustomDesignFromFileWithName:@"AlternativeDesign.json"];
[TSMessage showNotificationWithTitle:NSLocalizedString(@"Updated to custom design file", nil)
subtitle:NSLocalizedString(@"From now on, all the titles of success messages are larger", nil)
type:TSMessageNotificationTypeSuccess];
}
- (CGFloat)navigationbarBottomOfViewController:(UIViewController *)viewController
{
return 55;
}
@end