diff options
Diffstat (limited to 'Libraries external/REMenu')
-rw-r--r-- | Libraries external/REMenu/RECommonFunctions.h | 32 | ||||
-rwxr-xr-x | Libraries external/REMenu/RECommonFunctions.m | 44 | ||||
-rw-r--r-- | Libraries external/REMenu/REMenu.h | 119 | ||||
-rw-r--r-- | Libraries external/REMenu/REMenu.m | 421 | ||||
-rw-r--r-- | Libraries external/REMenu/REMenuContainerView.h | 33 | ||||
-rw-r--r-- | Libraries external/REMenu/REMenuContainerView.m | 66 | ||||
-rw-r--r-- | Libraries external/REMenu/REMenuItem.h | 69 | ||||
-rw-r--r-- | Libraries external/REMenu/REMenuItem.m | 120 | ||||
-rw-r--r-- | Libraries external/REMenu/REMenuItemView.h | 42 | ||||
-rw-r--r-- | Libraries external/REMenu/REMenuItemView.m | 241 |
10 files changed, 0 insertions, 1187 deletions
diff --git a/Libraries external/REMenu/RECommonFunctions.h b/Libraries external/REMenu/RECommonFunctions.h deleted file mode 100644 index ff5564d65..000000000 --- a/Libraries external/REMenu/RECommonFunctions.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// RECommonFunctions.h -// REMenu -// -// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) -// -// 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 <Foundation/Foundation.h> -#import <UIKit/UIKit.h> - -#ifndef REUIKitIsFlatModeFunction -#define REUIKitIsFlatModeFunction -BOOL REUIKitIsFlatMode(); -#endif
\ No newline at end of file diff --git a/Libraries external/REMenu/RECommonFunctions.m b/Libraries external/REMenu/RECommonFunctions.m deleted file mode 100755 index 6197253b1..000000000 --- a/Libraries external/REMenu/RECommonFunctions.m +++ /dev/null @@ -1,44 +0,0 @@ -// -// RECommonFunctions.m -// REMenu -// -// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) -// -// 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 "RECommonFunctions.h" - -BOOL REUIKitIsFlatMode() -{ - static BOOL isUIKitFlatMode = NO; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - if (floor(NSFoundationVersionNumber) > 993.0) { - // If your app is running in legacy mode, tintColor will be nil - else it must be set to some color. - if (UIApplication.sharedApplication.keyWindow) { - isUIKitFlatMode = [UIApplication.sharedApplication.delegate.window respondsToSelector:@selector(tintColor)]; - } else { - // Possible that we're called early on (e.g. when used in a Storyboard). Adapt and use a temporary window. - isUIKitFlatMode = [[UIWindow new] respondsToSelector:@selector(tintColor)]; - } - } - }); - return isUIKitFlatMode; -} diff --git a/Libraries external/REMenu/REMenu.h b/Libraries external/REMenu/REMenu.h deleted file mode 100644 index 816c656b4..000000000 --- a/Libraries external/REMenu/REMenu.h +++ /dev/null @@ -1,119 +0,0 @@ -// -// REMenu.h -// REMenu -// -// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) -// -// 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> -#import <QuartzCore/QuartzCore.h> -#import "RECommonFunctions.h" -#import "REMenuItem.h" -#import "REMenuContainerView.h" - -@class REMenuItem; - -typedef NS_ENUM(NSInteger, REMenuImageAlignment) { - REMenuImageAlignmentLeft, - REMenuImageAlignmentRight -}; - -typedef NS_ENUM(NSInteger, REMenuLiveBackgroundStyle) { - REMenuLiveBackgroundStyleLight, - REMenuLiveBackgroundStyleDark -}; - -@interface REMenu : NSObject - -// Menu View -// -@property (strong, readwrite, nonatomic) UIView *menuView; - -// Data -// -@property (strong, readwrite, nonatomic) NSArray *items; -@property (strong, readwrite, nonatomic) UIView *backgroundView; -@property (assign, readonly, nonatomic) BOOL isOpen; -@property (assign, readonly, nonatomic) BOOL isAnimating; -@property (assign, readwrite, nonatomic) BOOL waitUntilAnimationIsComplete; -@property (copy, readwrite, nonatomic) void (^closeCompletionHandler)(void); -@property (copy, readwrite, nonatomic) void (^closePreparationBlock)(void); -@property (assign, readwrite, nonatomic) BOOL closeOnSelection; - -// Style -// -@property (assign, readwrite, nonatomic) CGFloat cornerRadius; -@property (strong, readwrite, nonatomic) UIColor *shadowColor; -@property (assign, readwrite, nonatomic) CGSize shadowOffset; -@property (assign, readwrite, nonatomic) CGFloat shadowOpacity; -@property (assign, readwrite, nonatomic) CGFloat shadowRadius; -@property (assign, readwrite, nonatomic) CGFloat itemHeight; -@property (assign, readwrite, nonatomic) CGFloat backgroundAlpha; -@property (strong, readwrite, nonatomic) UIColor *backgroundColor; -@property (strong, readwrite, nonatomic) UIColor *separatorColor; -@property (assign, readwrite, nonatomic) CGFloat separatorHeight; -@property (assign, readwrite, nonatomic) CGSize separatorOffset; -@property (strong, readwrite, nonatomic) UIFont *font; -@property (strong, readwrite, nonatomic) UIColor *textColor; -@property (strong, readwrite, nonatomic) UIColor *textShadowColor; -@property (assign, readwrite, nonatomic) CGSize textOffset; -@property (assign, readwrite, nonatomic) CGSize textShadowOffset; -@property (assign, readwrite, nonatomic) REMenuImageAlignment imageAlignment; -@property (strong, readwrite, nonatomic) UIColor *imageTintColor; -@property (assign, readwrite, nonatomic) CGSize imageOffset; -@property (strong, readwrite, nonatomic) UIColor *highlightedBackgroundColor; -@property (strong, readwrite, nonatomic) UIColor *highlightedSeparatorColor; -@property (strong, readwrite, nonatomic) UIColor *highlightedTextColor; -@property (strong, readwrite, nonatomic) UIColor *highlightedTextShadowColor; -@property (strong, readwrite, nonatomic) UIColor *highlightedImageTintColor; -@property (assign, readwrite, nonatomic) CGSize highlightedTextShadowOffset; -@property (assign, readwrite, nonatomic) CGFloat borderWidth; -@property (strong, readwrite, nonatomic) UIColor *borderColor; -@property (assign, readwrite, nonatomic) NSTextAlignment textAlignment; -@property (strong, readwrite, nonatomic) UIFont *subtitleFont; -@property (strong, readwrite, nonatomic) UIColor *subtitleTextColor; -@property (strong, readwrite, nonatomic) UIColor *subtitleTextShadowColor; -@property (assign, readwrite, nonatomic) CGSize subtitleTextOffset; -@property (assign, readwrite, nonatomic) CGSize subtitleTextShadowOffset; -@property (strong, readwrite, nonatomic) UIColor *subtitleHighlightedTextColor; -@property (strong, readwrite, nonatomic) UIColor *subtitleHighlightedTextShadowColor; -@property (assign, readwrite, nonatomic) CGSize subtitleHighlightedTextShadowOffset; -@property (assign, readwrite, nonatomic) NSTextAlignment subtitleTextAlignment; -@property (assign, readwrite, nonatomic) NSTimeInterval animationDuration; -@property (assign, readwrite, nonatomic) NSTimeInterval closeAnimationDuration; -@property (assign, readwrite, nonatomic) NSTimeInterval bounceAnimationDuration; -@property (assign, readwrite, nonatomic) BOOL appearsBehindNavigationBar; -@property (assign, readwrite, nonatomic) BOOL bounce; -@property (assign, readwrite, nonatomic) BOOL liveBlur; // Available only in iOS 7 -@property (strong, readwrite, nonatomic) UIColor *liveBlurTintColor; // Available only in iOS 7 -@property (assign, readwrite, nonatomic) REMenuLiveBackgroundStyle liveBlurBackgroundStyle; // Available only in iOS 7 -@property (copy, readwrite, nonatomic) void (^badgeLabelConfigurationBlock)(UILabel *badgeLabel, REMenuItem *item); - -- (id)initWithItems:(NSArray *)items; -- (void)showFromRect:(CGRect)rect inView:(UIView *)view; -- (void)showInView:(UIView *)view; -- (void)showFromNavigationController:(UINavigationController *)navigationController; -- (void)showFromNavigationController:(UINavigationController *)navigationController offsetX:(CGFloat)offsetX width:(CGFloat)width; -- (void)setNeedsLayout; -- (void)closeWithCompletion:(void (^)(void))completion; -- (void)close; - -@end diff --git a/Libraries external/REMenu/REMenu.m b/Libraries external/REMenu/REMenu.m deleted file mode 100644 index 12108bce5..000000000 --- a/Libraries external/REMenu/REMenu.m +++ /dev/null @@ -1,421 +0,0 @@ -// -// REMenu.m -// REMenu -// -// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) -// -// 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 "REMenu.h" -#import "REMenuItem.h" -#import "REMenuItemView.h" - -@interface REMenuItem () - -@property (assign, readwrite, nonatomic) REMenuItemView *itemView; - -@end - -@interface REMenu () - -@property (strong, readwrite, nonatomic) UIView *menuWrapperView; -@property (strong, readwrite, nonatomic) REMenuContainerView *containerView; -@property (strong, readwrite, nonatomic) UIButton *backgroundButton; -@property (assign, readwrite, nonatomic) BOOL isOpen; -@property (assign, readwrite, nonatomic) BOOL isAnimating; -@property (strong, readwrite, nonatomic) NSMutableArray *itemViews; -@property (weak, readwrite, nonatomic) UINavigationBar *navigationBar; -@property (strong, readwrite, nonatomic) UIToolbar *toolbar; - -@end - -@implementation REMenu - -- (id)init -{ - self = [super init]; - if (self) { - _imageAlignment = REMenuImageAlignmentLeft; - _closeOnSelection = YES; - _itemHeight = 48.0; - _separatorHeight = 2.0; - _separatorOffset = CGSizeMake(0.0, 0.0); - _waitUntilAnimationIsComplete = YES; - - _textOffset = CGSizeMake(0, 0); - _subtitleTextOffset = CGSizeMake(0, 0); - _font = [UIFont boldSystemFontOfSize:21.0]; - _subtitleFont = [UIFont systemFontOfSize:14.0]; - - _backgroundAlpha = 1.0; - _backgroundColor = [UIColor colorWithRed:53/255.0 green:53/255.0 blue:52/255.0 alpha:1.0]; - _separatorColor = [UIColor colorWithPatternImage:self.separatorImage]; - _textColor = [UIColor colorWithRed:128/255.0 green:126/255.0 blue:124/255.0 alpha:1.0]; - _textShadowColor = [UIColor blackColor]; - _textShadowOffset = CGSizeMake(0, -1.0); - _textAlignment = NSTextAlignmentCenter; - - _highlightedBackgroundColor = [UIColor colorWithRed:28/255.0 green:28/255.0 blue:27/255.0 alpha:1.0]; - _highlightedSeparatorColor = [UIColor colorWithRed:28/255.0 green:28/255.0 blue:27/255.0 alpha:1.0]; - _highlightedTextColor = [UIColor colorWithRed:128/255.0 green:126/255.0 blue:124/255.0 alpha:1.0]; - _highlightedTextShadowColor = [UIColor blackColor]; - _highlightedTextShadowOffset = CGSizeMake(0, -1.0); - - _subtitleTextColor = [UIColor colorWithWhite:0.425 alpha:1.000]; - _subtitleTextShadowColor = [UIColor blackColor]; - _subtitleTextShadowOffset = CGSizeMake(0, -1.0); - _subtitleHighlightedTextColor = [UIColor colorWithRed:0.389 green:0.384 blue:0.379 alpha:1.000]; - _subtitleHighlightedTextShadowColor = [UIColor blackColor]; - _subtitleHighlightedTextShadowOffset = CGSizeMake(0, -1.0); - _subtitleTextAlignment = NSTextAlignmentCenter; - - _borderWidth = 1.0; - _borderColor = [UIColor colorWithRed:28/255.0 green:28/255.0 blue:27/255.0 alpha:1.0]; - _animationDuration = 0.3; - _closeAnimationDuration = 0.2; - _bounce = YES; - _bounceAnimationDuration = 0.2; - - _appearsBehindNavigationBar = REUIKitIsFlatMode() ? YES : NO; - } - return self; -} - -- (id)initWithItems:(NSArray *)items -{ - self = [self init]; - if (self) { - _items = items; - } - return self; -} - -- (void)showFromRect:(CGRect)rect inView:(UIView *)view -{ - if (self.isAnimating) { - return; - } - - self.isOpen = YES; - self.isAnimating = YES; - - // Create views - // - self.containerView = ({ - REMenuContainerView *view = [[REMenuContainerView alloc] init]; - view.clipsToBounds = YES; - view.autoresizingMask = UIViewAutoresizingFlexibleWidth; - - if (self.backgroundView) { - self.backgroundView.alpha = 0; - [view addSubview:self.backgroundView]; - } - view; - }); - - self.menuView = ({ - UIView *view = [[UIView alloc] init]; - if (!self.liveBlur || !REUIKitIsFlatMode()) { - view.backgroundColor = self.backgroundColor; - } - view.layer.cornerRadius = self.cornerRadius; - view.layer.borderColor = self.borderColor.CGColor; - view.layer.borderWidth = self.borderWidth; - view.layer.masksToBounds = YES; - view.layer.shouldRasterize = YES; - view.layer.rasterizationScale = [UIScreen mainScreen].scale; - view.autoresizingMask = UIViewAutoresizingFlexibleWidth; - view; - }); - - if (REUIKitIsFlatMode()) { - self.toolbar = ({ - UIToolbar *toolbar = [[UIToolbar alloc] init]; - toolbar.barStyle = (UIBarStyle)self.liveBlurBackgroundStyle; - if ([toolbar respondsToSelector:@selector(setBarTintColor:)]) - [toolbar performSelector:@selector(setBarTintColor:) withObject:self.liveBlurTintColor]; - toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth; - toolbar.layer.cornerRadius = self.cornerRadius; - toolbar.layer.borderColor = self.borderColor.CGColor; - toolbar.layer.borderWidth = self.borderWidth; - toolbar.layer.masksToBounds = YES; - toolbar; - }); - } - - self.menuWrapperView = ({ - UIView *view = [[UIView alloc] init]; - view.autoresizingMask = UIViewAutoresizingFlexibleWidth; - if (!self.liveBlur || !REUIKitIsFlatMode()) { - view.layer.shadowColor = self.shadowColor.CGColor; - view.layer.shadowOffset = self.shadowOffset; - view.layer.shadowOpacity = self.shadowOpacity; - view.layer.shadowRadius = self.shadowRadius; - view.layer.shouldRasterize = YES; - view.layer.rasterizationScale = [UIScreen mainScreen].scale; - } - view; - }); - - self.backgroundButton = ({ - UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - button.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - button.accessibilityLabel = NSLocalizedString(@"Menu background", @"Menu background"); - button.accessibilityHint = NSLocalizedString(@"Double tap to close", @"Double tap to close"); - [button addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside]; - button; - }); - - CGFloat navigationBarOffset = [self computeNavigationBarOffset]; - - // Append new item views to REMenuView - // - for (REMenuItem *item in self.items) { - NSInteger index = [self.items indexOfObject:item]; - - CGFloat itemHeight = self.itemHeight; - if (index == self.items.count - 1) - itemHeight += self.cornerRadius; - - UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(self.separatorOffset.width, - index * self.itemHeight + index * self.separatorHeight + 40.0 + navigationBarOffset + self.separatorOffset.height, - rect.size.width - self.separatorOffset.width, - self.separatorHeight)]; - separatorView.backgroundColor = self.separatorColor; - separatorView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - [self.menuView addSubview:separatorView]; - - REMenuItemView *itemView = [[REMenuItemView alloc] initWithFrame:CGRectMake(0, - index * self.itemHeight + (index + 1.0) * self.separatorHeight + 40.0 + navigationBarOffset, - rect.size.width, - itemHeight) - menu:self item:item - hasSubtitle:item.subtitle.length > 0]; - itemView.autoresizingMask = UIViewAutoresizingFlexibleWidth; - item.itemView = itemView; - itemView.separatorView = separatorView; - itemView.autoresizesSubviews = YES; - if (item.customView) { - item.customView.frame = itemView.bounds; - [itemView addSubview:item.customView]; - } - [self.menuView addSubview:itemView]; - } - - // Set up frames - // - self.menuWrapperView.frame = CGRectMake(0, -self.combinedHeight - navigationBarOffset, rect.size.width, self.combinedHeight + navigationBarOffset); - self.menuView.frame = self.menuWrapperView.bounds; - if (REUIKitIsFlatMode() && self.liveBlur) { - self.toolbar.frame = self.menuWrapperView.bounds; - } - self.containerView.frame = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); - self.backgroundButton.frame = self.containerView.bounds; - - // Add subviews - // - if (REUIKitIsFlatMode() && self.liveBlur) { - [self.menuWrapperView addSubview:self.toolbar]; - } - [self.menuWrapperView addSubview:self.menuView]; - [self.containerView addSubview:self.backgroundButton]; - [self.containerView addSubview:self.menuWrapperView]; - [view addSubview:self.containerView]; - - // Animate appearance - // - if (self.bounce) { - self.isAnimating = YES; - if ([UIView respondsToSelector:@selector(animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:)]) { - [UIView animateWithDuration:self.animationDuration+self.bounceAnimationDuration - delay:0.0 - usingSpringWithDamping:0.6 - initialSpringVelocity:4.0 - options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut - animations:^{ - self.backgroundView.alpha = self.backgroundAlpha; - CGRect frame = self.menuView.frame; - frame.origin.y = -40.0 - self.separatorHeight; - self.menuWrapperView.frame = frame; - } completion:^(BOOL finished) { - self.isAnimating = NO; - }]; - } else { - [UIView animateWithDuration:self.animationDuration - delay:0.0 - options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut - animations:^{ - self.backgroundView.alpha = self.backgroundAlpha; - CGRect frame = self.menuView.frame; - frame.origin.y = -40.0 - self.separatorHeight; - self.menuWrapperView.frame = frame; - } completion:^(BOOL finished) { - self.isAnimating = NO; - }]; - - } - } else { - [UIView animateWithDuration:self.animationDuration - delay:0.0 - options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut - animations:^{ - self.backgroundView.alpha = self.backgroundAlpha; - CGRect frame = self.menuView.frame; - frame.origin.y = -40.0 - self.separatorHeight; - self.menuWrapperView.frame = frame; - } completion:^(BOOL finished) { - self.isAnimating = NO; - }]; - } -} - -- (void)showInView:(UIView *)view -{ - [self showFromRect:view.bounds inView:view]; -} - --(void)showFromNavigationController:(UINavigationController *)navigationController -{ - [self showFromNavigationController:navigationController offsetX:0 width:navigationController.navigationBar.frame.size.width]; -} - -- (void)showFromNavigationController:(UINavigationController *)navigationController offsetX:(CGFloat)offsetX width:(CGFloat)width -{ - if (self.isAnimating) { - return; - } - - self.navigationBar = navigationController.navigationBar; - - [self showFromRect:CGRectMake(offsetX, 0, width, navigationController.view.frame.size.height) inView:navigationController.view]; - self.containerView.appearsBehindNavigationBar = self.appearsBehindNavigationBar; - self.containerView.navigationBar = navigationController.navigationBar; - if (self.appearsBehindNavigationBar) { - [navigationController.view bringSubviewToFront:navigationController.navigationBar]; - } - - if(width != navigationController.navigationBar.frame.size.width) - { - self.containerView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin; - } -} - -- (void)closeWithCompletion:(void (^)(void))completion -{ - if (self.isAnimating) return; - - self.isAnimating = YES; - - CGFloat navigationBarOffset = [self computeNavigationBarOffset]; - - void (^closeMenu)(void) = ^{ - [UIView animateWithDuration:self.closeAnimationDuration - delay:0.0 - options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut - animations:^ { - CGRect frame = self.menuView.frame; - frame.origin.y = - self.combinedHeight - navigationBarOffset; - self.menuWrapperView.frame = frame; - self.backgroundView.alpha = 0; - } completion:^(BOOL finished) { - self.isOpen = NO; - self.isAnimating = NO; - - [self.menuView removeFromSuperview]; - [self.menuWrapperView removeFromSuperview]; - [self.backgroundButton removeFromSuperview]; - [self.backgroundView removeFromSuperview]; - [self.containerView removeFromSuperview]; - - if (completion) { - completion(); - } - - if (self.closeCompletionHandler) { - self.closeCompletionHandler(); - } - }]; - - }; - - if (self.closePreparationBlock) { - self.closePreparationBlock(); - } - - if (self.bounce) { - [UIView animateWithDuration:self.bounceAnimationDuration animations:^{ - CGRect frame = self.menuView.frame; - frame.origin.y = -20.0; - self.menuWrapperView.frame = frame; - } completion:^(BOOL finished) { - closeMenu(); - }]; - } else { - closeMenu(); - } -} - -- (void)close -{ - [self closeWithCompletion:nil]; -} - -- (CGFloat)combinedHeight -{ - return self.items.count * self.itemHeight + self.items.count * self.separatorHeight + 40.0 + self.cornerRadius; -} - -- (void)setNeedsLayout -{ - [UIView animateWithDuration:0.35 animations:^{ - [self.containerView layoutSubviews]; - }]; -} - -#pragma mark - -#pragma mark Setting style - -- (UIImage *)separatorImage -{ - UIGraphicsBeginImageContext(CGSizeMake(1, 4.0)); - CGContextRef context = UIGraphicsGetCurrentContext(); - UIGraphicsPushContext(context); - CGContextSetFillColorWithColor(context, [UIColor colorWithRed:28/255.0 green:28/255.0 blue:27/255.0 alpha:1.0].CGColor); - CGContextFillRect(context, CGRectMake(0, 0, 1.0, 2.0)); - CGContextSetFillColorWithColor(context, [UIColor colorWithRed:79/255.0 green:79/255.0 blue:77/255.0 alpha:1.0].CGColor); - CGContextFillRect(context, CGRectMake(0, 3.0, 1.0, 2.0)); - UIGraphicsPopContext(); - UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - - return [UIImage imageWithCGImage:outputImage.CGImage scale:2.0 orientation:UIImageOrientationUp]; -} - -- (CGFloat)computeNavigationBarOffset -{ - //TWS - //CGFloat navigationBarOffset = self.appearsBehindNavigationBar && self.navigationBar ? ([UIApplication sharedApplication].statusBarHidden ? 44 : 64) : 0; - CGFloat navigationBarOffset = self.appearsBehindNavigationBar && self.navigationBar ? ([UIApplication sharedApplication].statusBarHidden ? 64 : 64) : 0; - - return navigationBarOffset; -} - - -@end diff --git a/Libraries external/REMenu/REMenuContainerView.h b/Libraries external/REMenu/REMenuContainerView.h deleted file mode 100644 index 47f3492bd..000000000 --- a/Libraries external/REMenu/REMenuContainerView.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// REMenuContainerView.h -// REMenu -// -// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) -// -// 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 REMenuContainerView : UIView - -@property (strong, readwrite, nonatomic) UINavigationBar *navigationBar; -@property (assign, readwrite, nonatomic) BOOL appearsBehindNavigationBar; - -@end diff --git a/Libraries external/REMenu/REMenuContainerView.m b/Libraries external/REMenu/REMenuContainerView.m deleted file mode 100644 index e01b31c18..000000000 --- a/Libraries external/REMenu/REMenuContainerView.m +++ /dev/null @@ -1,66 +0,0 @@ -// -// REMenuContainerView.m -// REMenu -// -// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) -// -// 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 "REMenuContainerView.h" -#import <QuartzCore/QuartzCore.h> - -@implementation REMenuContainerView - -- (void)layoutSubviews -{ - [super layoutSubviews]; - UIDeviceOrientation orientation = [UIDevice currentDevice].orientation; - - CGFloat landscapeOffset = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? 32.0 : 44.0; - - if (self.navigationBar && !self.appearsBehindNavigationBar) { - CGRect frame = self.frame; - frame.origin.y = self.navigationBar.frame.origin.y + (UIDeviceOrientationIsPortrait(orientation) ? 44.0 : landscapeOffset); - self.frame = frame; - } - - if (self.appearsBehindNavigationBar) { - CGRect frame = self.frame; - long height = [[UIScreen mainScreen] bounds].size.height; - - if (([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown) { - frame.origin.y = 0; - frame.size.height = height; - } else { - // landscape - if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { - frame.origin.y = -12; - frame.size.height = height + 12; - } else { - frame.origin.y = 0; - frame.size.height = height; - } - } - - self.frame = frame; - } -} - -@end diff --git a/Libraries external/REMenu/REMenuItem.h b/Libraries external/REMenu/REMenuItem.h deleted file mode 100644 index 9fc5d8f5f..000000000 --- a/Libraries external/REMenu/REMenuItem.h +++ /dev/null @@ -1,69 +0,0 @@ -// -// REMenuItem.h -// REMenu -// -// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) -// -// 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 <Foundation/Foundation.h> -#import <UIKit/UIKit.h> - -@interface REMenuItem : NSObject - -@property (strong, readwrite, nonatomic) UIColor *backgroundColor; -@property (strong, readwrite, nonatomic) UIColor *separatorColor; -@property (strong, readwrite, nonatomic) UIFont *font; -@property (strong, readwrite, nonatomic) UIColor *textColor; -@property (strong, readwrite, nonatomic) UIColor *textShadowColor; -@property (assign, readwrite, nonatomic) CGSize textOffset; -@property (assign, readwrite, nonatomic) CGSize textShadowOffset; -@property (strong, readwrite, nonatomic) UIColor *highlightedBackgroundColor; -@property (strong, readwrite, nonatomic) UIColor *highlightedSeparatorColor; -@property (strong, readwrite, nonatomic) UIColor *highlightedTextColor; -@property (strong, readwrite, nonatomic) UIColor *highlightedTextShadowColor; -@property (assign, readwrite, nonatomic) CGSize highlightedTextShadowOffset; -@property (assign, readwrite, nonatomic) NSTextAlignment textAlignment; -@property (strong, readwrite, nonatomic) UIFont *subtitleFont; -@property (strong, readwrite, nonatomic) UIColor *subtitleTextColor; -@property (strong, readwrite, nonatomic) UIColor *subtitleTextShadowColor; -@property (assign, readwrite, nonatomic) CGSize subtitleTextOffset; -@property (assign, readwrite, nonatomic) CGSize subtitleTextShadowOffset; -@property (strong, readwrite, nonatomic) UIColor *subtitleHighlightedTextColor; -@property (strong, readwrite, nonatomic) UIColor *subtitleHighlightedTextShadowColor; -@property (assign, readwrite, nonatomic) CGSize subtitleHighlightedTextShadowOffset; -@property (assign, readwrite, nonatomic) NSTextAlignment subtitleTextAlignment; - -@property (copy, readwrite, nonatomic) NSString *title; -@property (copy, readwrite, nonatomic) NSString *subtitle; -@property (copy, readwrite, nonatomic) NSString *badge; -@property (strong, readwrite, nonatomic) UIImage *image; -@property (strong, readwrite, nonatomic) UIImage *highlightedImage; -@property (copy, readwrite, nonatomic) void (^action)(REMenuItem *item); -@property (assign, readwrite, nonatomic) NSInteger tag; -@property (strong, readwrite, nonatomic) UIView *customView; - -- (id)initWithTitle:(NSString *)title image:(UIImage *)image highlightedImage:(UIImage *)highlightedImage action:(void (^)(REMenuItem *item))action; -- (id)initWithTitle:(NSString *)title subtitle:(NSString *)subtitle image:(UIImage *)image highlightedImage:(UIImage *)highlightedImage action:(void (^)(REMenuItem *item))action; -- (id)initWithCustomView:(UIView *)customView action:(void (^)(REMenuItem *item))action; -- (id)initWithCustomView:(UIView *)customView; -- (void)setNeedsLayout; - -@end diff --git a/Libraries external/REMenu/REMenuItem.m b/Libraries external/REMenu/REMenuItem.m deleted file mode 100644 index 3aaafe503..000000000 --- a/Libraries external/REMenu/REMenuItem.m +++ /dev/null @@ -1,120 +0,0 @@ -// -// REMenuItem.m -// REMenu -// -// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) -// -// 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 "REMenuItem.h" -#import "REMenuItemView.h" - -@interface REMenuItem () -@property (assign, nonatomic) REMenuItemView *itemView; -@end - - -@implementation REMenuItem - -- (id)initWithTitle:(NSString *)title image:(UIImage *)image highlightedImage:(UIImage *)highlightedImage action:(void (^)(REMenuItem *item))action -{ - self = [super init]; - if (self) { - _title = title; - _image = image; - _highlightedImage = highlightedImage; - _action = action; - _textAlignment = -1; - _subtitleTextAlignment = -1; - } - return self; -} - -- (id)initWithTitle:(NSString *)title subtitle:(NSString *)subtitle image:(UIImage *)image highlightedImage:(UIImage *)highlightedImage action:(void (^)(REMenuItem *item))action -{ - self = [super init]; - if (self) { - _title = title; - _subtitle = subtitle; - _image = image; - _highlightedImage = highlightedImage; - _action = action; - _textAlignment = -1; - _subtitleTextAlignment = -1; - } - return self; -} - -- (id)initWithCustomView:(UIView *)customView action:(void (^)(REMenuItem *item))action -{ - self = [super init]; - if (self) { - _customView = customView; - _action = action; - } - return self; -} - -- (id)initWithCustomView:(UIView *)customView -{ - self = [super init]; - if (self) { - _customView = customView; - } - return self; -} - -- (NSString *)description -{ - return [NSString stringWithFormat:@"<title: %@; subtitle: %@; tag: %li>", self.title, self.subtitle, (long)self.tag]; -} - -- (void)setTitle:(NSString *)title -{ - _title = title; - self.itemView.titleLabel.text = title; - self.itemView.accessibilityLabel = title; -} - -- (void)setSubtitle:(NSString *)subtitle -{ - _subtitle = subtitle; - self.itemView.subtitleLabel.text = subtitle; - self.itemView.accessibilityLabel = [NSString stringWithFormat:@"%@, %@", self.itemView.titleLabel.text, subtitle]; -} - -- (void)setImage:(UIImage *)image -{ - _image = image; - self.itemView.imageView.image = image; -} - -- (void)setHighlightedImage:(UIImage *)highlightedImage -{ - _highlightedImage = highlightedImage; - self.itemView.imageView.highlightedImage = highlightedImage; -} - -- (void)setNeedsLayout -{ - [self.itemView layoutSubviews]; -} - -@end diff --git a/Libraries external/REMenu/REMenuItemView.h b/Libraries external/REMenu/REMenuItemView.h deleted file mode 100644 index 87900523d..000000000 --- a/Libraries external/REMenu/REMenuItemView.h +++ /dev/null @@ -1,42 +0,0 @@ -// -// REMenuItemView.h -// REMenu -// -// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) -// -// 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> -#import "REMenuItem.h" -#import "REMenu.h" - -@interface REMenuItemView : UIView - -@property (weak, readwrite, nonatomic) REMenu *menu; -@property (weak, readwrite, nonatomic) UIView *separatorView; -@property (strong, readwrite, nonatomic) UILabel *titleLabel; -@property (strong, readwrite, nonatomic) UILabel *subtitleLabel; -@property (strong, readwrite, nonatomic) UIImageView *imageView; -@property (strong, readwrite, nonatomic) UILabel *badgeLabel; -@property (strong, readwrite, nonatomic) REMenuItem *item; - -- (id)initWithFrame:(CGRect)frame menu:(REMenu *)menu item:(REMenuItem*) item hasSubtitle:(BOOL)hasSubtitle; - -@end diff --git a/Libraries external/REMenu/REMenuItemView.m b/Libraries external/REMenu/REMenuItemView.m deleted file mode 100644 index 499a89199..000000000 --- a/Libraries external/REMenu/REMenuItemView.m +++ /dev/null @@ -1,241 +0,0 @@ -// -// REMenuItemView.m -// REMenu -// -// Copyright (c) 2013 Roman Efimov (https://github.com/romaonthego) -// -// 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 "REMenuItemView.h" -#import "REMenuItem.h" - -@interface REMenuItemView () - -@property (strong, readwrite, nonatomic) UIView *backgroundView; - -@end - -@implementation REMenuItemView - -- (id)initWithFrame:(CGRect)frame menu:(REMenu *)menu item:(REMenuItem*) item hasSubtitle:(BOOL)hasSubtitle -{ - self = [super initWithFrame:frame]; - if (self) { - self.menu = menu; - self.item = item; - self.isAccessibilityElement = YES; - self.accessibilityTraits = UIAccessibilityTraitButton; - self.accessibilityHint = NSLocalizedString(@"Double tap to choose", @"Double tap to choose"); - - _backgroundView = ({ - UIView *view = [[UIView alloc] initWithFrame:self.bounds]; - view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - if (menu.liveBlur && REUIKitIsFlatMode()) - view.alpha = 0.5f; - view; - }); - [self addSubview:_backgroundView]; - - - CGRect titleFrame; - if (hasSubtitle) { - // Dividing lines at 1/1.725 (vs 1/2.000) results in labels about 28-top 20-bottom or 60/40 title/subtitle (for a 48 frame height) - // - titleFrame = CGRectMake(self.item.textOffset.width == 0.0 && self.item.textOffset.height == 0.0 ? self.menu.textOffset.width : self.item.textOffset.width, self.item.textOffset.width == 0.0 && self.item.textOffset.height == 0.0 ? self.menu.textOffset.height : self.item.textOffset.height, 0, floorf(frame.size.height / 1.725)); - - CGRect subtitleFrame = CGRectMake(self.item.subtitleTextOffset.width == 0.0 && self.item.subtitleTextOffset.height == 0.0 ? self.menu.subtitleTextOffset.width : self.item.subtitleTextOffset.width, (self.item.subtitleTextOffset.width == 0.0 && self.item.subtitleTextOffset.height == 0.0 ? self.menu.subtitleTextOffset.height : self.item.subtitleTextOffset.height) + titleFrame.size.height, 0, floorf(frame.size.height * (1.0 - 1.0 / 1.725))); - self.subtitleLabel = ({ - UILabel *label =[[UILabel alloc] initWithFrame:subtitleFrame]; - label.contentMode = UIViewContentModeCenter; - label.textAlignment = (NSInteger)self.item.subtitleTextAlignment == -1 ? self.menu.subtitleTextAlignment : self.item.subtitleTextAlignment; - label.backgroundColor = [UIColor clearColor]; - label.autoresizingMask = UIViewAutoresizingFlexibleWidth; - label.isAccessibilityElement = NO; - label; - }); - [self addSubview:_subtitleLabel]; - } else { - titleFrame = CGRectMake(self.item.textOffset.width == 0.0 && self.item.textOffset.height == 0.0 ? self.menu.textOffset.width : self.item.textOffset.width, self.item.textOffset.width == 0.0 && self.item.textOffset.height == 0.0 ? self.menu.textOffset.height : self.item.textOffset.height, 0, frame.size.height); - } - - _titleLabel = ({ - UILabel *label = [[UILabel alloc] initWithFrame:titleFrame]; - label.isAccessibilityElement = NO; - label.contentMode = UIViewContentModeCenter; - label.textAlignment = (NSInteger)self.item.textAlignment == -1 ? self.menu.textAlignment : self.item.subtitleTextAlignment; - label.backgroundColor = [UIColor clearColor]; - label.autoresizingMask = UIViewAutoresizingFlexibleWidth; - label; - }); - - _imageView = [[UIImageView alloc] initWithFrame:CGRectNull]; - - _badgeLabel = ({ - UILabel *label = [[UILabel alloc] init]; - label.backgroundColor = [UIColor colorWithWhite:0.559 alpha:1.000]; - label.font = [UIFont systemFontOfSize:11]; - label.textAlignment = NSTextAlignmentCenter; - label.textColor = [UIColor whiteColor]; - label.hidden = YES; - label.layer.cornerRadius = 4.0; - label.layer.borderColor = [UIColor colorWithWhite:0.630 alpha:1.000].CGColor; - label.layer.borderWidth = 1.0; - label.layer.masksToBounds = YES; - label; - }); - - [self addSubview:_titleLabel]; - [self addSubview:_imageView]; - [self addSubview:_badgeLabel]; - } - return self; -} - -- (void)layoutSubviews -{ - [super layoutSubviews]; - - self.imageView.image = self.item.image; - - // Adjust frames - // - CGFloat verticalOffset = floor((self.frame.size.height - self.item.image.size.height) / 2.0); - CGFloat horizontalOffset = floor((self.menu.itemHeight - self.item.image.size.height) / 2.0); - CGFloat x = (self.menu.imageAlignment == REMenuImageAlignmentLeft) ? horizontalOffset + self.menu.imageOffset.width : - self.titleLabel.frame.size.width - (horizontalOffset + self.menu.imageOffset.width + self.item.image.size.width); - self.imageView.frame = CGRectMake(x, verticalOffset + self.menu.imageOffset.height, self.item.image.size.width, self.item.image.size.height); - if ([self.imageView respondsToSelector:@selector(setTintColor:)]) { - self.imageView.tintColor = self.menu.imageTintColor; - } - - // Set up badge - // - self.badgeLabel.hidden = !self.item.badge; - if (self.item.badge) { - self.badgeLabel.text = self.item.badge; - NSAttributedString *badgeAttributedString = [[NSAttributedString alloc] initWithString:self.item.badge - attributes:@{NSFontAttributeName:self.badgeLabel.font}]; - CGRect rect = [badgeAttributedString boundingRectWithSize:CGSizeMake(CGRectGetMaxX(self.frame), CGRectGetMaxY(self.frame)) - options:NSStringDrawingUsesLineFragmentOrigin - context:nil]; - CGFloat x = self.menu.imageAlignment == REMenuImageAlignmentLeft ? CGRectGetMaxX(self.imageView.frame) - 2.0 : - CGRectGetMinX(self.imageView.frame) - rect.size.height - 4.0; - self.badgeLabel.frame = CGRectMake(x, self.imageView.frame.origin.y - 2.0, rect.size.width + 6.0, rect.size.height + 2.0); - - if (self.menu.badgeLabelConfigurationBlock) - self.menu.badgeLabelConfigurationBlock(self.badgeLabel, self.item); - } - - // Accessibility - // - self.accessibilityLabel = self.item.title; - if (self.subtitleLabel.text) - self.accessibilityLabel = [NSString stringWithFormat:@"%@, %@", self.item.title, self.item.subtitle]; - - // Adjust styles - // - self.backgroundView.backgroundColor = self.item.backgroundColor == nil ? [UIColor clearColor] : self.item.backgroundColor; - self.titleLabel.font = self.item.font == nil ? self.menu.font : self.item.font; - self.titleLabel.text = self.item.title; - self.titleLabel.textColor = self.item.textColor == nil ? self.menu.textColor : self.item.textColor; - self.titleLabel.shadowColor = self.item.textShadowColor ? self.menu.textShadowColor : self.item.textShadowColor; - self.titleLabel.shadowOffset = self.item.textShadowOffset.width == 0 && self.item.textShadowOffset.height == 0 ? self.menu.textShadowOffset : self.item.textShadowOffset; - self.titleLabel.textAlignment = (NSInteger)self.item.textAlignment == -1 ? self.menu.textAlignment : self.item.textAlignment; - self.subtitleLabel.font = self.item.subtitleFont == nil ? self.menu.subtitleFont : self.item.subtitleFont -; - self.subtitleLabel.text = self.item.subtitle; - self.subtitleLabel.textColor = self.item.subtitleTextColor == nil ? self.menu.subtitleTextColor : self.item.subtitleTextColor; - self.subtitleLabel.shadowColor = self.item.subtitleTextShadowColor == nil ? self.menu.subtitleTextShadowColor : self.item.subtitleTextShadowColor; - self.subtitleLabel.shadowOffset = self.item.subtitleTextShadowOffset.width == 0 && self.item.subtitleTextShadowOffset.height == 0 ? self.menu.subtitleTextShadowOffset : self.item.subtitleTextShadowOffset; - self.subtitleLabel.textAlignment = (NSInteger)self.item.subtitleTextAlignment == -1 ? self.menu.subtitleTextAlignment : self.item.subtitleTextAlignment; - - self.item.customView.frame = CGRectMake(0, 0, self.titleLabel.frame.size.width, self.frame.size.height); -} - -- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event -{ - self.backgroundView.backgroundColor = self.item.highlightedBackgroundColor == nil ? self.menu.highlightedBackgroundColor : self.item.highlightedBackgroundColor; - self.separatorView.backgroundColor = self.item.highlightedSeparatorColor == nil ? self.menu.highlightedSeparatorColor : self.item.highlightedSeparatorColor; - self.imageView.image = self.item.highlightedImage ? self.item.highlightedImage : self.item.image; - if ([self.imageView respondsToSelector:@selector(setTintColor:)]) { - self.imageView.tintColor = self.menu.highlightedImageTintColor; - } - self.titleLabel.textColor = self.item.highlightedTextColor == nil ? self.menu.highlightedTextColor : self.item.highlightedTextColor; - self.titleLabel.shadowColor = self.item.highlightedTextShadowColor == nil ? self.menu.highlightedTextShadowColor : self.item.highlightedTextShadowColor; - self.titleLabel.shadowOffset = self.item.highlightedTextShadowOffset.width == 0 && self.item.highlightedTextShadowOffset.height == 0 ? self.menu.highlightedTextShadowOffset : self.item.highlightedTextShadowOffset; - self.subtitleLabel.textColor = self.item.subtitleHighlightedTextColor == nil ? self.menu.subtitleHighlightedTextColor : self.item.subtitleHighlightedTextColor; - self.subtitleLabel.shadowColor = self.item.subtitleHighlightedTextShadowColor == nil ? self.menu.subtitleHighlightedTextShadowColor : self.item.subtitleHighlightedTextShadowColor; - self.subtitleLabel.shadowOffset = self.item.subtitleHighlightedTextShadowOffset.width == 0 && self.item.subtitleHighlightedTextShadowOffset.height == 0 ? self.menu.subtitleHighlightedTextShadowOffset : self.item.subtitleHighlightedTextShadowOffset; -} - -- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event -{ - self.backgroundView.backgroundColor = self.item.backgroundColor == nil ? [UIColor clearColor] : self.item.backgroundColor; - self.separatorView.backgroundColor = self.menu.separatorColor; - self.imageView.image = self.item.image; - if ([self.imageView respondsToSelector:@selector(setTintColor:)]) { - self.imageView.tintColor = self.menu.imageTintColor; - } - self.titleLabel.textColor = self.item.textColor == nil ? self.menu.textColor : self.item.textColor; - self.titleLabel.shadowColor = self.item.textShadowColor == nil ?self.menu.textShadowColor : self.item.textShadowColor; - self.titleLabel.shadowOffset = self.item.textShadowOffset.width == 0 && self.item.textShadowOffset.height == 0 ? self.menu.textShadowOffset : self.item.textShadowOffset; - self.subtitleLabel.textColor = self.item.subtitleTextColor == nil ? self.menu.subtitleTextColor : self.item.subtitleTextColor; - self.subtitleLabel.shadowColor = self.item.subtitleTextShadowColor == nil ? self.menu.subtitleTextShadowColor : self.item.subtitleTextShadowColor; - self.subtitleLabel.shadowOffset = self.item.subtitleTextShadowOffset.width == 0 && self.item.subtitleTextShadowOffset.height == 0 ? self.menu.subtitleTextShadowOffset : self.item.subtitleTextShadowOffset; -} - -- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event -{ - self.backgroundView.backgroundColor = self.item.backgroundColor == nil ? [UIColor clearColor] : self.item.backgroundColor; - self.separatorView.backgroundColor = self.item.separatorColor == nil ? self.menu.separatorColor : self.item.separatorColor; - self.imageView.image = self.item.image; - if ([self.imageView respondsToSelector:@selector(setTintColor:)]) { - self.imageView.tintColor = self.menu.imageTintColor; - } - self.titleLabel.textColor = self.item.textColor == nil ? self.menu.textColor : self.item.textColor; - self.titleLabel.shadowColor = self.item.textShadowColor == nil ? self.menu.textShadowColor : self.item.textShadowColor; - self.titleLabel.shadowOffset = self.item.textShadowOffset.width == 0 && self.item.textShadowOffset.height ? self.menu.textShadowOffset : self.item.textShadowOffset; - self.subtitleLabel.textColor = self.item.subtitleTextColor == nil ? self.menu.subtitleTextColor : self.item.subtitleTextColor; - self.subtitleLabel.shadowColor = self.menu.subtitleTextShadowColor == nil ? self.menu.subtitleTextShadowColor : self.item.subtitleTextShadowColor; - self.subtitleLabel.shadowOffset = self.item.subtitleTextShadowOffset.width == 0 && self.item.subtitleTextShadowOffset.height == 0 ? self.menu.subtitleTextShadowOffset : self.item.subtitleTextShadowOffset; - - CGPoint endedPoint = [touches.anyObject locationInView:self]; - if (endedPoint.y < 0 || endedPoint.y > CGRectGetHeight(self.bounds)) - return; - - if (!self.menu.closeOnSelection) { - if (self.item.action) - self.item.action(self.item); - } else { - if (self.item.action) { - if (self.menu.waitUntilAnimationIsComplete) { - __typeof (&*self) __weak weakSelf = self; - [self.menu closeWithCompletion:^{ - weakSelf.item.action(weakSelf.item); - }]; - } else { - [self.menu close]; - self.item.action(self.item); - } - } - } -} - -@end |