Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e2d2826e6c | |||
| 8bd01ad27c | |||
| 2c9bc8677c |
@@ -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
|
||||
|
||||
@@ -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];
|
||||
```
|
||||
|
||||

|
||||
|
||||
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 |
Reference in New Issue
Block a user