Compare commits

...

3 Commits

Author SHA1 Message Date
Cezary Wojcik e2d2826e6c 2.1.0
added custom display/dismiss methods
2013-11-17 10:11:56 -08:00
Cezary Wojcik 8bd01ad27c Updated screenshot 2013-11-17 00:57:43 -08:00
Cezary Wojcik 2c9bc8677c Updated README and screenshots 2013-11-17 00:56:20 -08:00
6 changed files with 43 additions and 21 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CWStatusBarNotification"
s.version = "2.0.0"
s.version = "2.1.0"
s.summary = "A library that creates status bar notifications."
s.description = "CWStatusBarNotification is a library allows you to present a beautiful text-based notification in the status bar."
s.homepage = "http://github.com/cezarywojcik/CWStatusBarNotification"
@@ -36,5 +36,7 @@ enum {
@property (strong, nonatomic) UIWindow *notificationWindow;
- (void)displayNotificationWithMessage:(NSString *)message forDuration:(CGFloat)duration;
- (void)displayNotificationWithMessage:(NSString *)message completion:(void (^)(void))completion;
- (void)dismissNotification;
@end
@@ -208,7 +208,7 @@
# pragma mark - display notification
- (void)displayNotificationWithMessage:(NSString *)message forDuration:(CGFloat)duration
- (void)displayNotificationWithMessage:(NSString *)message completion:(void (^)(void))completion
{
if (!self.notificationIsShowing) {
self.notificationIsShowing = YES;
@@ -234,25 +234,37 @@
[UIView animateWithDuration:STATUS_BAR_ANIMATION_LENGTH animations:^{
[self firstFrameChange];
} completion:^(BOOL finished) {
[UIView animateWithDuration:duration - 2*STATUS_BAR_ANIMATION_LENGTH animations:^{
// potential animations while notification is showing
} completion:^(BOOL finished) {
[self secondFrameChange];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[UIView animateWithDuration:STATUS_BAR_ANIMATION_LENGTH animations:^{
[self thirdFrameChange];
} completion:^(BOOL finished) {
[self.notificationLabel removeFromSuperview];
[self.statusBarView removeFromSuperview];
self.notificationWindow = nil;
self.notificationIsShowing = NO;
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
}];
});
}];
[completion invoke];
}];
}
}
- (void)dismissNotification
{
if (self.notificationIsShowing) {
[self secondFrameChange];
[UIView animateWithDuration:STATUS_BAR_ANIMATION_LENGTH animations:^{
[self thirdFrameChange];
} completion:^(BOOL finished) {
[self.notificationLabel removeFromSuperview];
[self.statusBarView removeFromSuperview];
self.notificationWindow = nil;
self.notificationIsShowing = NO;
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
}];
}
}
- (void)displayNotificationWithMessage:(NSString *)message forDuration:(CGFloat)duration
{
[self displayNotificationWithMessage:message completion:^{
double delayInSeconds = duration;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self dismissNotification];
});
}];
}
@end
+10 -2
View File
@@ -42,6 +42,14 @@ After you have a `CWStatusBarNotification` object, you can simply call the `disp
forDuration:1.0f];
```
If you prefer to manually choose when to display and dismiss the notification, you can do so as well:
```
[self.notification displayNotificationWithMessage:@"Hello" completion:nil];
// wait until you need to dismiss
[self.notofication dismissNotification];
```
## Customizing Appearance
First of all, you can customize the background color and text color using the following properties: `notificationLabelBackgroundColor` and `notificationLabelTextColor`.
@@ -49,8 +57,8 @@ First of all, you can customize the background color and text color using the fo
Example:
```
notification.notificationLabelBackgroundColor = [UIColor redColor];
notification.notificationLabelTextColor = [UIColor yellowColor];
notification.notificationLabelBackgroundColor = [UIColor blackColor];
notification.notificationLabelTextColor = [UIColor greenColor];
```
![custom colors](screenshots/ss1.gif)
Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 138 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 237 KiB