diff options
| author | mo khan <mo@mokhan.ca> | 2013-07-14 14:41:58 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-07-14 14:41:58 -0600 |
| commit | ec7be9ac0cb94f008f1160a0c42ad2a1cfc17f49 (patch) | |
| tree | 970fed448c965b05b186ee4bd7d403906adbd7e2 /Pods/TSMessages | |
| parent | b0c7b44d56c564d26291b7c5e7f0add8f72c7de2 (diff) | |
add progress message pods:
Diffstat (limited to 'Pods/TSMessages')
25 files changed, 1185 insertions, 0 deletions
diff --git a/Pods/TSMessages/Classes/TSMessage.h b/Pods/TSMessages/Classes/TSMessage.h new file mode 100755 index 0000000..5a23a17 --- /dev/null +++ b/Pods/TSMessages/Classes/TSMessage.h @@ -0,0 +1,157 @@ +// +// TSMessage.h +// Toursprung +// +// Created by Felix Krause on 24.08.12. +// Copyright (c) 2012 Toursprung. All rights reserved. +// + +#import <UIKit/UIKit.h> + +typedef enum { + TSMessageNotificationTypeMessage = 0, + TSMessageNotificationTypeWarning, + TSMessageNotificationTypeError, + TSMessageNotificationTypeSuccess +} TSMessageNotificationType; + +typedef enum { + TSMessageNotificationPositionTop = 0, + TSMessageNotificationPositionBottom +} TSMessageNotificationPosition; + +/** This enum can be passed to the duration parameter */ +typedef enum { + TSMessageNotificationDurationAutomatic = 0, + TSMessageNotificationDurationEndless = -1 // The notification is displayed until the user dismissed it or it is dismissed by calling dismissActiveNotification +} TSMessageNotificationDuration; + + +@interface TSMessage : NSObject + ++ (instancetype)sharedMessage; + +/** Indicates whether a notification is currently active. */ ++ (BOOL)isNotificationActive; + +/** Shows a notification message + @param message The title of the notification view + @param type The notification type (Message, Warning, Error, Success) + */ ++ (void)showNotificationWithMessage:(NSString *)message + withType:(TSMessageNotificationType)type; + +/** Shows a notification message + @param title The title of the notification view + @param message The message that is displayed underneath the title + @param type The notification type (Message, Warning, Error, Success) + */ ++ (void)showNotificationWithTitle:(NSString *)title + withMessage:(NSString *)message + withType:(TSMessageNotificationType)type; + +/** Shows a notification message in a specific view controller + @param viewController The view controller to show the notification in. + @param title The title of the notification view + @param message The message that is displayed underneath the title + @param type The notification type (Message, Warning, Error, Success) + */ ++ (void)showNotificationInViewController:(UIViewController *)viewController + withTitle:(NSString *)title + withMessage:(NSString *)message + withType:(TSMessageNotificationType)type; + +/** Shows a notification message in a specific view controller + @param viewController The view controller to show the notification in. + @param title The title of the notification view + @param message The message that is displayed underneath the title + @param type The notification type (Message, Warning, Error, Success) + @param duration The duration of the notification being displayed + */ ++ (void)showNotificationInViewController:(UIViewController *)viewController + withTitle:(NSString *)title + withMessage:(NSString *)message + withType:(TSMessageNotificationType)type + withDuration:(NSTimeInterval)duration; + +/** Shows a notification message in a specific view controller + @param viewController The view controller to show the notification in. + @param title The title of the notification view + @param message The message that is displayed underneath the title + @param type The notification type (Message, Warning, Error, Success) + @param duration The duration of the notification being displayed + @param callback The block that should be executed, when the user tapped on the message + */ ++ (void)showNotificationInViewController:(UIViewController *)viewController + withTitle:(NSString *)title + withMessage:(NSString *)message + withType:(TSMessageNotificationType)type + withDuration:(NSTimeInterval)duration + withCallback:(void (^)())callback; + +/** Shows a notification message in a specific view controller + @param viewController The view controller to show the notification in. + @param title The title of the notification view + @param message The message that is displayed underneath the title + @param type The notification type (Message, Warning, Error, Success) + @param duration The duration of the notification being displayed + @param callback The block that should be executed, when the user tapped on the message + @param position The position of the message on the screen + */ ++ (void)showNotificationInViewController:(UIViewController *)viewController + withTitle:(NSString *)title + withMessage:(NSString *)message + withType:(TSMessageNotificationType)type + withDuration:(NSTimeInterval)duration + withCallback:(void (^)())callback + atPosition:(TSMessageNotificationPosition)messagePosition; + +/** Shows a notification message in a specific view controller + @param viewController The view controller to show the notification in. + @param title The title of the notification view + @param message The message that is displayed underneath the title + @param type The notification type (Message, Warning, Error, Success) + @param duration The duration of the notification being displayed + @param callback The block that should be executed, when the user tapped on the message + @param buttonTitle The title for button (optional) + @param buttonCallback The block that should be executed, when the user tapped on the button + @param position The position of the message on the screen + @param dismissingEnabled Should the message be dismissed when the user taps/swipes it + */ ++ (void)showNotificationInViewController:(UIViewController *)viewController + withTitle:(NSString *)title + withMessage:(NSString *)message + withType:(TSMessageNotificationType)type + withDuration:(NSTimeInterval)duration + withCallback:(void (^)())callback + withButtonTitle:(NSString *)buttonTitle + withButtonCallback:(void (^)())buttonCallback + atPosition:(TSMessageNotificationPosition)messagePosition + canBeDismisedByUser:(BOOL)dismissingEnabled; + + +/** Fades out the currently displayed notification. If another notification is in the queue, + the next one will be displayed automatically + @return YES if the currently displayed notification could be hidden. NO if no notification + was currently displayed. + */ ++ (BOOL)dismissActiveNotification; + + + +/** Shows a predefined error message, that is displayed, when this action requires an internet connection */ ++ (void)showInternetError; + +/** Shows a predefined error message, that is displayed, when this action requires location services */ ++ (void)showLocationError; + + + + +/** Implement this in subclass to set a default view controller */ ++ (UIViewController *)defaultViewController; + +/** Can be implemented differently in subclass. Is used to define the top position from which the notification flies in from */ ++ (CGFloat)navigationbarBottomOfViewController:(UIViewController *)viewController; + +@end diff --git a/Pods/TSMessages/Classes/TSMessage.m b/Pods/TSMessages/Classes/TSMessage.m new file mode 100755 index 0000000..dc198af --- /dev/null +++ b/Pods/TSMessages/Classes/TSMessage.m @@ -0,0 +1,340 @@ +// +// TSMessage.m +// Toursprung +// +// Created by Felix Krause on 24.08.12. +// Copyright (c) 2012 Toursprung. All rights reserved. +// + +#import "TSMessage.h" +#import "TSMessageView.h" + +#define kTSMessageDisplayTime 1.5 +#define kTSMessageExtraDisplayTimePerPixel 0.04 +#define kTSMessageAnimationDuration 0.3 + +@interface TSMessage () + +/** The queued messages (TSMessageView objects) */ +@property (nonatomic, strong) NSMutableArray *messages; + +- (void)fadeInCurrentNotification; +- (void)fadeOutNotification:(TSMessageView *)currentView; + +@end + +@implementation TSMessage + +static TSMessage *sharedMessages; +static BOOL notificationActive; + + ++ (TSMessage *)sharedMessage +{ + if (!sharedMessages) + { + sharedMessages = [[[self class] alloc] init]; + } + return sharedMessages; +} + ++ (BOOL)isNotificationActive +{ + return notificationActive; +} + +#pragma mark Methods to call from outside + ++ (void)showNotificationWithMessage:(NSString *)message + withType:(TSMessageNotificationType)type +{ + [self showNotificationWithTitle:message withMessage:nil withType:type]; +} + ++ (void)showNotificationWithTitle:(NSString *)title + withMessage:(NSString *)message + withType:(TSMessageNotificationType)type +{ + [self showNotificationInViewController:[self defaultViewController] + withTitle:title + withMessage:message + withType:type]; +} + ++ (void)showNotificationInViewController:(UIViewController *)viewController + withTitle:(NSString *)title + withMessage:(NSString *)message + withType:(TSMessageNotificationType)type +{ + [self showNotificationInViewController:viewController + withTitle:title + withMessage:message + withType:type + withDuration:0.0]; +} + ++ (void)showNotificationInViewController:(UIViewController *)viewController + withTitle:(NSString *)title + withMessage:(NSString *)message + withType:(TSMessageNotificationType)type + withDuration:(NSTimeInterval)duration +{ + [self showNotificationInViewController:viewController + withTitle:title + withMessage:message + withType:type + withDuration:duration + withCallback:nil]; +} + ++ (void)showNotificationInViewController:(UIViewController *)viewController + withTitle:(NSString *)title + withMessage:(NSString *)message + withType:(TSMessageNotificationType)type + withDuration:(NSTimeInterval)duration + withCallback:(void (^)())callback +{ + [self showNotificationInViewController:viewController + withTitle:title + withMessage:message + withType:type + withDuration:duration + withCallback:callback + atPosition:TSMessageNotificationPositionTop]; +} + ++ (void)showNotificationInViewController:(UIViewController *)viewController + withTitle:(NSString *)title + withMessage:(NSString *)message + withType:(TSMessageNotificationType)type + withDuration:(NSTimeInterval)duration + withCallback:(void (^)())callback + atPosition:(TSMessageNotificationPosition)messagePosition +{ + [self showNotificationInViewController:viewController + withTitle:title + withMessage:message + withType:type + withDuration:duration + withCallback:callback + withButtonTitle:nil + withButtonCallback:nil + atPosition:messagePosition + canBeDismisedByUser:YES]; +} + + ++ (void)showNotificationInViewController:(UIViewController *)viewController + withTitle:(NSString *)title + withMessage:(NSString *)message + withType:(TSMessageNotificationType)type + withDuration:(NSTimeInterval)duration + withCallback:(void (^)())callback + withButtonTitle:(NSString *)buttonTitle + withButtonCallback:(void (^)())buttonCallback + atPosition:(TSMessageNotificationPosition)messagePosition + canBeDismisedByUser:(BOOL)dismissingEnabled +{ + for (TSMessageView *n in [TSMessage sharedMessage].messages) + { + if (([n.title isEqualToString:title] || (!n.title && !title)) && ([n.content isEqualToString:message] || (!n.content && !message))) + { + return; // avoid showing the same messages twice in a row + } + } + + // Create the TSMessageView + TSMessageView *v = [[TSMessageView alloc] initWithTitle:title + withContent:message + withType:type + withDuration:duration + inViewController:viewController + withCallback:callback + withButtonTitle:buttonTitle + withButtonCallback:buttonCallback + atPosition:messagePosition + shouldBeDismissed:dismissingEnabled]; + + [[TSMessage sharedMessage].messages addObject:v]; + + if (!notificationActive) + { + [[TSMessage sharedMessage] fadeInCurrentNotification]; + } +} + +#pragma mark Example uses + ++ (void)showInternetError +{ + [TSMessage showNotificationWithTitle:NSLocalizedString(@"Network error", nil) + withMessage:NSLocalizedString(@"Couldn't connect to the server. Check your network connection.", nil) + withType:TSMessageNotificationTypeError]; +} + ++ (void)showLocationError +{ + [TSMessage showNotificationWithTitle:NSLocalizedString(@"Location error", nil) + withMessage:NSLocalizedString(@"Couldn't detect your current location.", nil) + withType:TSMessageNotificationTypeError]; +} + + +#pragma mark Setting up of notification views + +- (id)init +{ + if ((self = [super init])) + { + _messages = [[NSMutableArray alloc] init]; + } + return self; +} + +- (void)fadeInCurrentNotification +{ + if ([self.messages count] == 0) return; + + notificationActive = YES; + + TSMessageView *currentView = [self.messages objectAtIndex:0]; + + CGFloat verticalOffset = 0.0f; + + if ([currentView.viewController isKindOfClass:[UINavigationController class]]) + { + if (![(UINavigationController *)currentView.viewController isNavigationBarHidden]) + { + [currentView.viewController.view insertSubview:currentView + belowSubview:[(UINavigationController *)currentView.viewController navigationBar]]; + verticalOffset = [(UINavigationController *)currentView.viewController navigationBar].bounds.size.height; + + if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) + { + verticalOffset += [UIApplication sharedApplication].statusBarFrame.size.height; + } + else + { + verticalOffset += [UIApplication sharedApplication].statusBarFrame.size.width; + } + } + else + { + [currentView.viewController.view addSubview:currentView]; + } + } + else + { + [currentView.viewController.view addSubview:currentView]; + } + + CGPoint toPoint; + if (currentView.messagePosition == TSMessageNotificationPositionTop) + { + toPoint = CGPointMake(currentView.center.x, + [[self class] navigationbarBottomOfViewController:currentView.viewController] + verticalOffset + CGRectGetHeight(currentView.frame) / 2.0); + } + else + { + toPoint = CGPointMake(currentView.center.x, + currentView.viewController.view.bounds.size.height - CGRectGetHeight(currentView.frame) / 2.0); + } + + [UIView animateWithDuration:kTSMessageAnimationDuration animations:^ + { + currentView.center = toPoint; + currentView.alpha = TSMessageViewAlpha; + } completion:^(BOOL finished) { + currentView.messageIsFullyDisplayed = YES; + }]; + + + if (currentView.duration == TSMessageNotificationDurationAutomatic) + { + currentView.duration = kTSMessageAnimationDuration + kTSMessageDisplayTime + currentView.frame.size.height * kTSMessageExtraDisplayTimePerPixel; + } + + if (currentView.duration != TSMessageNotificationDurationEndless) + { + dispatch_async(dispatch_get_main_queue(), ^ + { + [self performSelector:@selector(fadeOutNotification:) + withObject:currentView + afterDelay:currentView.duration]; + }); + } +} + +- (void)fadeOutNotification:(TSMessageView *)currentView +{ + currentView.messageIsFullyDisplayed = NO; + [NSObject cancelPreviousPerformRequestsWithTarget:self + selector:@selector(fadeOutNotification:) + object:currentView]; + + CGPoint fadeOutToPoint; + if (currentView.messagePosition == TSMessageNotificationPositionTop) + { + fadeOutToPoint = CGPointMake(currentView.center.x, -CGRectGetHeight(currentView.frame) / 2.0);; + } + else + { + fadeOutToPoint = CGPointMake(currentView.center.x, + currentView.viewController.view.bounds.size.height); + } + + [UIView animateWithDuration:kTSMessageAnimationDuration animations:^ + { + currentView.center = fadeOutToPoint; + currentView.alpha = 0.0; + } + completion:^(BOOL finished) + { + [currentView removeFromSuperview]; + + if ([self.messages count] > 0) + { + [self.messages removeObjectAtIndex:0]; + } + + notificationActive = NO; + + if ([self.messages count] > 0) + { + [self fadeInCurrentNotification]; + } + }]; +} + ++ (BOOL)dismissActiveNotification +{ + if ([[TSMessage sharedMessage].messages count] == 0) return NO; + + dispatch_async(dispatch_get_main_queue(), ^ + { + TSMessageView *currentMessage = [[TSMessage sharedMessage].messages objectAtIndex:0]; + if (currentMessage.messageIsFullyDisplayed) + { + [[TSMessage sharedMessage] fadeOutNotification:currentMessage]; + } + }); + return YES; +} + +#pragma mark class Methods to subclass + ++ (UIViewController *)defaultViewController +{ + NSLog(@"No view controller was set as parameter and TSMessage was not subclassed. If you want to subclass, implement defaultViewController to set the default viewController."); + return nil; + // Implement this in subclass +} + + ++ (CGFloat)navigationbarBottomOfViewController:(UIViewController *)viewController +{ + return 0; + // Implement this in subclass +} + +@end diff --git a/Pods/TSMessages/Classes/UIColorAdditions/UIColor+MLColorAdditions.h b/Pods/TSMessages/Classes/UIColorAdditions/UIColor+MLColorAdditions.h new file mode 100755 index 0000000..60124da --- /dev/null +++ b/Pods/TSMessages/Classes/UIColorAdditions/UIColor+MLColorAdditions.h @@ -0,0 +1,22 @@ +// +// UIColor+UIColor_MLColorAdditions.h +// +// Created by Marius Landwehr on 02.12.12. +// The MIT License (MIT) +// Copyright (c) 2012 Marius Landwehr marius.landwehr@gmail.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +#import <UIKit/UIKit.h> + +@interface UIColor (MLColorAdditions) + ++ (UIColor *)colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha; ++ (UIColor *)colorWith8BitRed:(NSInteger)red green:(NSInteger)green blue:(NSInteger)blue alpha:(CGFloat)alpha; + +@end diff --git a/Pods/TSMessages/Classes/UIColorAdditions/UIColor+MLColorAdditions.m b/Pods/TSMessages/Classes/UIColorAdditions/UIColor+MLColorAdditions.m new file mode 100755 index 0000000..f630343 --- /dev/null +++ b/Pods/TSMessages/Classes/UIColorAdditions/UIColor+MLColorAdditions.m @@ -0,0 +1,49 @@ +// +// UIColor+MLColorAdditions.m +// +// Created by Marius Landwehr on 02.12.12. +// The MIT License (MIT) +// Copyright (c) 2012 Marius Landwehr marius.landwehr@gmail.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +#import "UIColor+MLColorAdditions.h" + +@implementation UIColor (MLColorAdditions) + + ++ (UIColor *)colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha +{ + assert(7 == hexString.length); + assert('#' == [hexString characterAtIndex:0]); + + NSString *redHex = [NSString stringWithFormat:@"0x%@", [hexString substringWithRange:NSMakeRange(1, 2)]]; + NSString *greenHex = [NSString stringWithFormat:@"0x%@", [hexString substringWithRange:NSMakeRange(3, 2)]]; + NSString *blueHex = [NSString stringWithFormat:@"0x%@", [hexString substringWithRange:NSMakeRange(5, 2)]]; + + unsigned redInt = 0; + NSScanner *redScanner = [NSScanner scannerWithString:redHex]; + [redScanner scanHexInt:&redInt]; + + unsigned greenInt = 0; + NSScanner *greenScanner = [NSScanner scannerWithString:greenHex]; + [greenScanner scanHexInt:&greenInt]; + + unsigned blueInt = 0; + NSScanner *blueScanner = [NSScanner scannerWithString:blueHex]; + [blueScanner scanHexInt:&blueInt]; + + return [UIColor colorWith8BitRed:redInt green:greenInt blue:blueInt alpha:alpha]; +} + ++ (UIColor *)colorWith8BitRed:(NSInteger)red green:(NSInteger)green blue:(NSInteger)blue alpha:(CGFloat)alpha +{ + return [UIColor colorWithRed:(float)red/255 green:(float)green/255 blue:(float)blue/255 alpha:alpha]; +} + +@end diff --git a/Pods/TSMessages/LICENSE b/Pods/TSMessages/LICENSE new file mode 100644 index 0000000..bd6134a --- /dev/null +++ b/Pods/TSMessages/LICENSE @@ -0,0 +1,8 @@ +Copyright (c) 2013, Toursprung +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file diff --git a/Pods/TSMessages/README.md b/Pods/TSMessages/README.md new file mode 100644 index 0000000..97c6b7f --- /dev/null +++ b/Pods/TSMessages/README.md @@ -0,0 +1,91 @@ +TSMessages +========== + +This framework provides an easy to use class to show little notification views on the top of the screen. (à la Tweetbot). + +The notification moves from the top of the screen underneath the navigation bar and stays there for a few seconds, depending on the length of the displayed text. To dismiss a notification before the time runs out, the user can swipe it to the top or just tap it. + +There are 4 different types already set up for you: Success, Error, Warning, Message (take a look at the screenshots) + +It is very easy to add new notification types with a different design. Add the new type to the notificationType enum, add the needed design properties to the configuration file and set the name of the theme (used in the config file and images) in TSMessagesView.m inside the switch case. + +**Take a look at the Example project to see how to use this library.** You have to open the workspace, not the project file, since the Example project uses cocoapods. + +Follow the developer on Twitter: [KrauseFx](http://twitter.com/krausefx) (Felix Krause) + +## Installation + +### From CocoaPods + +Add `pod 'TSMessages'` to your Podfile. + +### Manually + +Drag the whole folder into your project and remove the example project. This library requires ARC. + +To show notifications use the following code: +-------- + +```objective-c + [TSMessage showNotificationInViewController:self + withTitle:notificationTitle + withMessage:notificationDescription + withType:TSMessageNotificationTypeError]; + + + [TSMessage showNotificationInViewController:self + withTitle:title + withMessage:message + withType:TSMessageNotificationTypeSuccess + withDuration:15.0 + withCallback:^{ + // user dismissed callback + }]; +``` + +The following properties can be set: + +* **viewController**: The view controller to show the notification in. This might be the navigation controller. +* **title**: The title of the notification view +* **message**: The message that is displayed underneath the title. +* **type**: The notification type (Message, Warning, Error, Success) +* **duration**: The duration the notification should be displayed +* **callback**: The block that should be executed, when the user dismissed the message by tapping on it or swiping it to the top. + +Except the title and the notification type, all of the listed values are optional + +You don't need to do anything with TSMessageView, except you want to modify the behavior or the types of the notification itself. + +If you don't want a detailed description (the text underneath the title) you don't need to set one. The notification will automatically resize itself properly. There are different initializer available. + + + + + + +This project requires ARC. + +If you have ideas how to improve this library please let me know or send a pull request. + +Changes +----- +**0.9.3** + +* Added new customization options for buttons (font size, custom background image, separate font and shadow color) +* Added method to dismiss the currently active message +* Added option to show a message until it is dismissed by the user +* Added option to disable dismissing notification by the user +* Added method to check whether a notification is currently being displayed +* Fixed auto rotation when notification is displayed on the bottom + +**0.9.2** + +* Added option to show message on the bottom of the screen +* Added option to show a button inside the message + + + + +TODOs +----- +Currently empty
\ No newline at end of file diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundError.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundError.png Binary files differnew file mode 100755 index 0000000..2a9c763 --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundError.png diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundError@2x.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundError@2x.png Binary files differnew file mode 100755 index 0000000..3c53de6 --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundError@2x.png diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundErrorIcon.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundErrorIcon.png Binary files differnew file mode 100755 index 0000000..f5429a3 --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundErrorIcon.png diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundErrorIcon@2x.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundErrorIcon@2x.png Binary files differnew file mode 100755 index 0000000..dce47d9 --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundErrorIcon@2x.png diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundMessage.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundMessage.png Binary files differnew file mode 100755 index 0000000..1c8cf92 --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundMessage.png diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundMessage@2x.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundMessage@2x.png Binary files differnew file mode 100755 index 0000000..d842f01 --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundMessage@2x.png diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundSuccess.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundSuccess.png Binary files differnew file mode 100755 index 0000000..b9b7e57 --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundSuccess.png diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundSuccess@2x.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundSuccess@2x.png Binary files differnew file mode 100755 index 0000000..61457ad --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundSuccess@2x.png diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundSuccessIcon.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundSuccessIcon.png Binary files differnew file mode 100755 index 0000000..19eddfd --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundSuccessIcon.png diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundSuccessIcon@2x.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundSuccessIcon@2x.png Binary files differnew file mode 100755 index 0000000..01ead80 --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundSuccessIcon@2x.png diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundWarning.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundWarning.png Binary files differnew file mode 100755 index 0000000..e7a0290 --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundWarning.png diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundWarning@2x.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundWarning@2x.png Binary files differnew file mode 100755 index 0000000..3583214 --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundWarning@2x.png diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundWarningIcon.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundWarningIcon.png Binary files differnew file mode 100755 index 0000000..220b3cc --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundWarningIcon.png diff --git a/Pods/TSMessages/Resources/Images/NotificationBackgroundWarningIcon@2x.png b/Pods/TSMessages/Resources/Images/NotificationBackgroundWarningIcon@2x.png Binary files differnew file mode 100755 index 0000000..ef276e8 --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationBackgroundWarningIcon@2x.png diff --git a/Pods/TSMessages/Resources/Images/NotificationButtonBackground.png b/Pods/TSMessages/Resources/Images/NotificationButtonBackground.png Binary files differnew file mode 100644 index 0000000..d59b415 --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationButtonBackground.png diff --git a/Pods/TSMessages/Resources/Images/NotificationButtonBackground@2x.png b/Pods/TSMessages/Resources/Images/NotificationButtonBackground@2x.png Binary files differnew file mode 100644 index 0000000..7cda5ca --- /dev/null +++ b/Pods/TSMessages/Resources/Images/NotificationButtonBackground@2x.png diff --git a/Pods/TSMessages/Resources/design.json b/Pods/TSMessages/Resources/design.json new file mode 100644 index 0000000..7a2deda --- /dev/null +++ b/Pods/TSMessages/Resources/design.json @@ -0,0 +1,74 @@ +{ + "success": { + "backgroundImageName": "NotificationBackgroundSuccess.png", + "borderColor": "#005700", + "borderHeight": 1, + "buttonBackgroundImageName": "NotificationButtonBackground.png", + "buttonTitleTextColor": "#FFFFFF", + "buttonTitleShadowColor": "#67B759", + "buttonTitleShadowOffsetX": 0, + "buttonTitleShadowOffsetY": -1, + "contentFontSize": 12, + "contentTextColor": "#FFFFFF", + "imageName": "NotificationBackgroundSuccessIcon.png", + "shadowColor": "#67B759", + "shadowOffsetX": 0, + "shadowOffsetY": -1, + "textColor": "#FFFFFF", + "titleFontSize": 14 + }, + "message": { + "backgroundImageName": "NotificationBackgroundMessage.png", + "borderColor": "#727C83", + "borderHeight": 1, + "buttonBackgroundImageName": "NotificationButtonBackground.png", + "buttonTitleTextColor": "#727C83", + "buttonTitleShadowColor": "#EBEEF1", + "buttonTitleShadowOffsetX": 0, + "buttonTitleShadowOffsetY": 1, + "contentFontSize": 12, + "contentTextColor": "#727C83", + "imageName": "", + "shadowColor": "#EBEEF1", + "shadowOffsetX": 0, + "shadowOffsetY": 1, + "textColor": "#727C83", + "titleFontSize": 14 + }, + "warning": { + "backgroundImageName": "NotificationBackgroundWarning.png", + "borderColor": "#A28918", + "borderHeight": 1, + "buttonBackgroundImageName": "NotificationButtonBackground.png", + "buttonTitleTextColor": "#484638", + "buttonTitleShadowColor": "#E5D87C", + "buttonTitleShadowOffsetX": 0, + "buttonTitleShadowOffsetY": 1, + "contentFontSize": 12, + "contentTextColor": "#484638", + "imageName": "NotificationBackgroundWarningIcon.png", + "shadowColor": "#E5D87C", + "shadowOffsetX": 0, + "shadowOffsetY": 1, + "textColor": "#484638", + "titleFontSize": 14 + }, + "error": { + "backgroundImageName": "NotificationBackgroundError.png", + "borderColor": "#700000", + "borderHeight": 1, + "buttonBackgroundImageName": "NotificationButtonBackground.png", + "buttonTitleTextColor": "#FFFFFF", + "buttonTitleShadowColor": "#812929", + "buttonTitleShadowOffsetX": 0, + "buttonTitleShadowOffsetY": -1, + "contentFontSize": 12, + "contentTextColor": "#FFFFFF", + "imageName": "NotificationBackgroundErrorIcon.png", + "shadowColor": "#812929", + "shadowOffsetX": 0, + "shadowOffsetY": -1, + "textColor": "#FFFFFF", + "titleFontSize": 14 + } +}
\ No newline at end of file diff --git a/Pods/TSMessages/Views/TSMessageView.h b/Pods/TSMessages/Views/TSMessageView.h new file mode 100755 index 0000000..3464374 --- /dev/null +++ b/Pods/TSMessages/Views/TSMessageView.h @@ -0,0 +1,60 @@ +// +// TSMessageView.h +// Toursprung +// +// Created by Felix Krause on 24.08.12. +// Copyright (c) 2012 Toursprung. All rights reserved. +// + +#import <UIKit/UIKit.h> +#import "TSMessage.h" + +#define TSMessageViewAlpha 0.95 + +@interface TSMessageView : UIView + +/** The displayed title of this message */ +@property (nonatomic, readonly) NSString *title; + +/** The displayed content of this message (optional) */ +@property (nonatomic, readonly) NSString *content; + +/** The view controller this message is displayed in */ +@property (nonatomic, readonly) UIViewController *viewController; + +/** The duration of the displayed message. If it is 0.0, it will automatically be calculated */ +@property (nonatomic, assign) CGFloat duration; + +/** The position of the message (top or bottom) */ +@property (nonatomic, assign) TSMessageNotificationPosition messagePosition; + +/** Is the message currenlty fully displayed? Is set as soon as the message is really fully visible */ +@property (nonatomic, assign) BOOL messageIsFullyDisplayed; + +/** Inits the notification view. Do not call this from outside this library. + @param title The title of the notification view + @param content The subtitle/content of the notification view (optional) + @param notificationType The type (color) of the notification view + @param duration The duration this notification should be displayed (optional) + @param viewController The view controller this message should be displayed in + @param callback The block that should be executed, when the user tapped on the message + @param buttonTitle The title for button (optional) + @param buttonCallback The block that should be executed, when the user tapped on the button + @param position The position of the message on the screen + @param dismissAble Should this message be dismissed when the user taps/swipes it? + */ +- (id)initWithTitle:(NSString *)title + withContent:(NSString *)content + withType:(TSMessageNotificationType)notificationType + withDuration:(CGFloat)duration + inViewController:(UIViewController *)viewController + withCallback:(void (^)())callback + withButtonTitle:(NSString *)buttonTitle + withButtonCallback:(void (^)())buttonCallback + atPosition:(TSMessageNotificationPosition)position + shouldBeDismissed:(BOOL)dismissAble; + +/** Fades out this notification view */ +- (void)fadeMeOut; + +@end diff --git a/Pods/TSMessages/Views/TSMessageView.m b/Pods/TSMessages/Views/TSMessageView.m new file mode 100755 index 0000000..2910d00 --- /dev/null +++ b/Pods/TSMessages/Views/TSMessageView.m @@ -0,0 +1,384 @@ +// +// TSMessageView.m +// Toursprung +// +// Created by Felix Krause on 24.08.12. +// Copyright (c) 2012 Toursprung. All rights reserved. +// + +#import "TSMessageView.h" +#import "UIColor+MLColorAdditions.h" + +#define TSMessageViewPadding 15.0 + +#define TSDesignFileName @"design.json" + +static NSDictionary *notificationDesign; + +@interface TSMessageView () + +@property (nonatomic, strong) NSString *title; +@property (nonatomic, strong) NSString *content; +@property (nonatomic, strong) NSString *buttonTitle; +@property (nonatomic, strong) UIViewController *viewController; + +/** Internal properties needed to resize the view on device rotation properly */ +@property (nonatomic, strong) UILabel *titleLabel; +@property (nonatomic, strong) UILabel *contentLabel; +@property (nonatomic, strong) UIImageView *iconImageView; +@property (nonatomic, strong) UIButton *button; +@property (nonatomic, strong) UIView *borderView; +@property (nonatomic, strong) UIImageView *backgroundImageView; + +@property (nonatomic, assign) CGFloat textSpaceLeft; +@property (nonatomic, assign) CGFloat textSpaceRight; + +@property (copy) void (^callback)(); +@property (copy) void (^buttonCallback)(); + +- (CGFloat)updateHeightOfMessageView; +- (void)layoutSubviews; + +@end + + +@implementation TSMessageView + +- (id)initWithTitle:(NSString *)title + withContent:(NSString *)content + withType:(TSMessageNotificationType)notificationType + withDuration:(CGFloat)duration + inViewController:(UIViewController *)viewController + withCallback:(void (^)())callback + withButtonTitle:(NSString *)buttonTitle + withButtonCallback:(void (^)())buttonCallback + atPosition:(TSMessageNotificationPosition)position + shouldBeDismissed:(BOOL)dismissAble +{ + if (!notificationDesign) + { + NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:TSDesignFileName]; + notificationDesign = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfFile:path] + options:kNilOptions + error:nil]; + } + + if ((self = [self init])) + { + _title = title; + _content = content; + _buttonTitle = buttonTitle; + _duration = duration; + _viewController = viewController; + _messagePosition = position; + self.callback = callback; + self.buttonCallback = buttonCallback; + + CGFloat screenWidth = self.viewController.view.bounds.size.width; + NSDictionary *current; + NSString *currentString; + switch (notificationType) + { + case TSMessageNotificationTypeMessage: + { + currentString = @"message"; + break; + } + case TSMessageNotificationTypeError: + { + currentString = @"error"; + break; + } + case TSMessageNotificationTypeSuccess: + { + currentString = @"success"; + break; + } + case TSMessageNotificationTypeWarning: + { + currentString = @"warning"; + break; + } + + default: + break; + } + + current = [notificationDesign valueForKey:currentString]; + + self.alpha = 0.0; + + UIImage *image; + if ([current valueForKey:@"imageName"]) + { + image = [UIImage imageNamed:[current valueForKey:@"imageName"]]; + } + + // add background image here + UIImage *backgroundImage = [[UIImage imageNamed:[current valueForKey:@"backgroundImageName"]] stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0]; + _backgroundImageView = [[UIImageView alloc] initWithImage:backgroundImage]; + self.backgroundImageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth); + [self addSubview:self.backgroundImageView]; + + UIColor *fontColor = [UIColor colorWithHexString:[current valueForKey:@"textColor"] + alpha:1.0]; + + + self.textSpaceLeft = 2 * TSMessageViewPadding; + if (image) self.textSpaceLeft += image.size.width + 2 * TSMessageViewPadding; + + // Set up title label + _titleLabel = [[UILabel alloc] init]; + [self.titleLabel setText:title]; + [self.titleLabel setTextColor:fontColor]; + [self.titleLabel setBackgroundColor:[UIColor clearColor]]; + [self.titleLabel setFont:[UIFont boldSystemFontOfSize:[[current valueForKey:@"titleFontSize"] floatValue]]]; + [self.titleLabel setShadowColor:[UIColor colorWithHexString:[current valueForKey:@"shadowColor"] alpha:1.0]]; + [self.titleLabel setShadowOffset:CGSizeMake([[current valueForKey:@"shadowOffsetX"] floatValue], + [[current valueForKey:@"shadowOffsetY"] floatValue])]; + self.titleLabel.numberOfLines = 0; + self.titleLabel.lineBreakMode = NSLineBreakByWordWrapping; + [self addSubview:self.titleLabel]; + + // Set up content label (if set) + if ([content length]) + { + _contentLabel = [[UILabel alloc] init]; + [self.contentLabel setText:content]; + + UIColor *contentTextColor = [UIColor colorWithHexString:[current valueForKey:@"contentTextColor"] alpha:1.0]; + if (!contentTextColor) + { + contentTextColor = fontColor; + } + [self.contentLabel setTextColor:contentTextColor]; + [self.contentLabel setBackgroundColor:[UIColor clearColor]]; + [self.contentLabel setFont:[UIFont systemFontOfSize:[[current valueForKey:@"contentFontSize"] floatValue]]]; + [self.contentLabel setShadowColor:self.titleLabel.shadowColor]; + [self.contentLabel setShadowOffset:self.titleLabel.shadowOffset]; + self.contentLabel.lineBreakMode = self.titleLabel.lineBreakMode; + self.contentLabel.numberOfLines = 0; + + [self addSubview:self.contentLabel]; + } + + if (image) + { + _iconImageView = [[UIImageView alloc] initWithImage:image]; + self.iconImageView.frame = CGRectMake(TSMessageViewPadding * 2, + TSMessageViewPadding, + image.size.width, + image.size.height); + [self addSubview:self.iconImageView]; + } + + // Set up button (if set) + if ([buttonTitle length]) + { + _button = [UIButton buttonWithType:UIButtonTypeCustom]; + + UIImage *buttonBackgroundImage = [[UIImage imageNamed:[current valueForKey:@"buttonBackgroundImageName"]] resizableImageWithCapInsets:UIEdgeInsetsMake(15.0, 12.0, 15.0, 11.0)]; + + if (!buttonBackgroundImage) + { + buttonBackgroundImage = [[UIImage imageNamed:[current valueForKey:@"NotificationButtonBackground"]] resizableImageWithCapInsets:UIEdgeInsetsMake(15.0, 12.0, 15.0, 11.0)]; + } + + [self.button setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal]; + [self.button setTitle:self.buttonTitle forState:UIControlStateNormal]; + + UIColor *buttonTitleShadowColor = [UIColor colorWithHexString:[current valueForKey:@"buttonTitleShadowColor"] alpha:1.0]; + if (!buttonTitleShadowColor) + { + buttonTitleShadowColor = self.titleLabel.shadowColor; + } + + [self.button setTitleShadowColor:buttonTitleShadowColor forState:UIControlStateNormal]; + + UIColor *buttonTitleTextColor = [UIColor colorWithHexString:[current valueForKey:@"buttonTitleTextColor"] alpha:1.0]; + if (!buttonTitleTextColor) + { + buttonTitleTextColor = fontColor; + } + + [self.button setTitleColor:buttonTitleTextColor forState:UIControlStateNormal]; + self.button.titleLabel.font = [UIFont boldSystemFontOfSize:14.0]; + self.button.titleLabel.shadowOffset = CGSizeMake([[current valueForKey:@"buttonTitleShadowOffsetX"] floatValue], + [[current valueForKey:@"buttonTitleShadowOffsetY"] floatValue]); + [self.button addTarget:self + action:@selector(buttonTapped:) + forControlEvents:UIControlEventTouchUpInside]; + + self.button.contentEdgeInsets = UIEdgeInsetsMake(0.0, 5.0, 0.0, 5.0); + [self.button sizeToFit]; + self.button.frame = CGRectMake(screenWidth - TSMessageViewPadding - self.button.frame.size.width, + 0.0, + self.button.frame.size.width, + 31.0); + + [self addSubview:self.button]; + + self.textSpaceRight = self.button.frame.size.width + TSMessageViewPadding; + } + + // Add a border on the bottom (or on the top, depending on the view's postion) + _borderView = [[UIView alloc] initWithFrame:CGRectMake(0.0, + 0.0, // will be set later + screenWidth, + [[current valueForKey:@"borderHeight"] floatValue])]; + self.borderView.backgroundColor = [UIColor colorWithHexString:[current valueForKey:@"borderColor"] + alpha:1.0]; + self.borderView.autoresizingMask = (UIViewAutoresizingFlexibleWidth); + [self addSubview:self.borderView]; + + + CGFloat actualHeight = [self updateHeightOfMessageView]; // this call also takes care of positioning the labels + CGFloat topPosition = -actualHeight; + + if (self.messagePosition == TSMessageNotificationPositionBottom) + { + topPosition = self.viewController.view.bounds.size.height; + } + + self.frame = CGRectMake(0.0, topPosition, screenWidth, actualHeight); + + if (self.messagePosition == TSMessageNotificationPositionTop) + { + self.autoresizingMask = UIViewAutoresizingFlexibleWidth; + } + else + { + self.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin); + } + + if (dismissAble) + { + UISwipeGestureRecognizer *gestureRec = [[UISwipeGestureRecognizer alloc] initWithTarget:self + action:@selector(fadeMeOut)]; + [gestureRec setDirection:(self.messagePosition == TSMessageNotificationPositionTop ? + UISwipeGestureRecognizerDirectionUp : + UISwipeGestureRecognizerDirectionDown)]; + [self addGestureRecognizer:gestureRec]; + + UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc] initWithTarget:self + action:@selector(fadeMeOut)]; + [self addGestureRecognizer:tapRec]; + } + } + return self; +} + + +- (CGFloat)updateHeightOfMessageView +{ + CGFloat currentHeight; + CGFloat screenWidth = self.viewController.view.bounds.size.width; + + + self.titleLabel.frame = CGRectMake(self.textSpaceLeft, + TSMessageViewPadding, + screenWidth - TSMessageViewPadding - self.textSpaceLeft - self.textSpaceRight, + 0.0); + [self.titleLabel sizeToFit]; + + if ([self.content length]) + { + self.contentLabel.frame = CGRectMake(self.textSpaceLeft, + self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height + 5.0, + screenWidth - TSMessageViewPadding - self.textSpaceLeft - self.textSpaceRight, + 0.0); + [self.contentLabel sizeToFit]; + + currentHeight = self.contentLabel.frame.origin.y + self.contentLabel.frame.size.height; + } + else + { + // only the title was set + currentHeight = self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height; + } + + currentHeight += TSMessageViewPadding; + + if (self.iconImageView) + { + // Check if that makes the popup larger (height) + if (self.iconImageView.frame.origin.y + self.iconImageView.frame.size.height + TSMessageViewPadding > currentHeight) + { + currentHeight = self.iconImageView.frame.origin.y + self.iconImageView.frame.size.height; + } + else + { + // z-align + self.iconImageView.center = CGPointMake([self.iconImageView center].x, + round(currentHeight / 2.0)); + } + } + + // z-align button + self.button.center = CGPointMake([self.button center].x, + round(currentHeight / 2.0)); + + if (self.messagePosition == TSMessageNotificationPositionTop) + { + // Correct the border position + CGRect borderFrame = self.borderView.frame; + borderFrame.origin.y = currentHeight; + self.borderView.frame = borderFrame; + } + + currentHeight += self.borderView.frame.size.height; + + self.frame = CGRectMake(0.0, self.frame.origin.y, self.frame.size.width, currentHeight); + + + if (self.button) + { + self.button.frame = CGRectMake(self.frame.size.width - self.textSpaceRight, + round((self.frame.size.height / 2.0) - self.button.frame.size.height / 2.0), + self.button.frame.size.width, + self.button.frame.size.height); + } + + + self.backgroundImageView.frame = CGRectMake(self.backgroundImageView.frame.origin.x, + self.backgroundImageView.frame.origin.y, + screenWidth, + currentHeight); + + return currentHeight; +} + +- (void)layoutSubviews +{ + [super layoutSubviews]; + [self updateHeightOfMessageView]; +} + +- (void)fadeMeOut +{ + // user tapped on the message + dispatch_async(dispatch_get_main_queue(), ^ + { + if (self.callback) + { + self.callback(); + } + + [[TSMessage sharedMessage] performSelector:@selector(fadeOutNotification:) + withObject:self]; + }); +} + +#pragma mark - UIButton target + +- (void)buttonTapped:(id) sender +{ + if (self.buttonCallback) + { + self.buttonCallback(); + } + + [self fadeMeOut]; +} + +@end |
