Release 1.0.0

This commit is contained in:
giuseppenuc committed 2015-10-29 01:04:32 +01:00
1 parent 5ecc0d4203
commit 40cdd4eb91
111 files changed
+5910 -1769

No files matched your search

+7
View File
@@ -47,6 +47,11 @@
*/
@property (nonatomic, strong) NSString *itemName;
/**
* Represents the name of the item that can be shown in picker.
*/
@property (nonatomic, strong) NSString *itemSearchKey;
/**
* Represents the sub items that appeare when you select the item in picker.
*/
@@ -74,4 +79,6 @@
- (void) setHighlighted:(BOOL) highlighted;
- (void) setSelected:(BOOL)selected;
@end
+27 -8
View File
@@ -12,7 +12,7 @@
#import "UIButton+BackgroundColor.h"
#import <UIKit/UIKit.h>
@interface TabBarItem()
@interface TabBarItem() <TabBarPickerSubItemsViewDelegate>
@property (nonatomic, strong) UIButton *itemButton;
@@ -39,20 +39,20 @@
_orientation = [[UIDevice currentDevice] orientation];
_itemSubView = itemSubView;
_itemButton = [[UIButton alloc] initForAutoLayout];
_highlightedColor = [@"ff4e50" colorFromHex];
_itemButton = [UIButton newAutoLayoutView];
[_itemButton addTarget:self action:@selector(itemButtonTapped) forControlEvents:UIControlEventTouchUpInside];
[_itemButton setBackgroundColor:[@"ff4e50" colorFromHex] forState:UIControlStateHighlighted];
[_itemButton setBackgroundColor:_highlightedColor forState:UIControlStateHighlighted];
[_itemButton setBackgroundColor:_highlightedColor forState:UIControlStateSelected|UIControlStateHighlighted];
[self addSubview:_itemButton];
}
return self;
}
- (void) layoutSubviews {
//[_itemButton autoPinEdgesToSuperviewMargins];
if (!_didSetupConstraints) {
[_itemButton autoCenterInSuperview];
[_itemButton autoSetDimension:ALDimensionHeight toSize:44];
@@ -62,6 +62,14 @@
}
}
- (void) setTag:(NSInteger)tag {
[super setTag:tag];
for (UIView *subView in self.subviews) {
[subView setTag:tag];
}
[_itemSubView setTag:tag];
}
- (void)deviceOrientationDidChange:(NSNotification *)notification {
//Obtain current device orientation
_orientation = [[UIDevice currentDevice] orientation];
@@ -76,29 +84,40 @@
- (void) setSelectedImage:(UIImage *)selectedImage {
[_itemButton setImage:selectedImage forState:UIControlStateSelected];
[_itemButton setImage:selectedImage forState:UIControlStateSelected|UIControlStateHighlighted];
//[_itemButton setImage:selectedImage forState:UIControlStateSelected|UIControlStateHighlighted];
}
- (void) setHighlightedImage:(UIImage *)highlightedImage {
[_itemButton setImage:highlightedImage forState:UIControlStateHighlighted];
[_itemButton setImage:highlightedImage forState:UIControlStateHighlighted|UIControlStateNormal];
[_itemButton setImage:highlightedImage forState:UIControlStateSelected|UIControlStateHighlighted];
}
- (void) setHighlightedColor:(UIColor *)highlightedColor {
_highlightedColor = highlightedColor;
[_itemButton setBackgroundColor:_highlightedColor forState:UIControlStateHighlighted];
}
- (void) setHighlighted:(BOOL) highlighted {
[_itemButton setHighlighted:highlighted];
}
- (void) setSelected:(BOOL)selected {
[_itemButton setSelected:selected];
}
- (void) setItemName:(NSString *)itemName {
[_itemSubView setItemName:itemName];
_itemName = itemName;
}
- (void) itemButtonTapped {
if (_delegate && [_delegate respondsToSelector:@selector(tabBarItemSelected:)]) {
[_delegate tabBarItemSelected:self];
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.00001 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.000001 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self setHighlighted:YES];
});
}
+12
View File
@@ -11,6 +11,15 @@
#import "TabBarSubItem.h"
#import "TabBarPickerSubItemsView.h"
@class TabBarPicker;
@protocol TabBarPickerDelegate <NSObject>
- (void) TabBarPicker:(TabBarPicker*) picker filtersDidChanges:(NSDictionary *) filtersEnabled;
@end
typedef NS_ENUM(NSInteger, TabBarPickerPosition) {
// Informational
TabBarPickerPositionLeft,
@@ -31,6 +40,9 @@ typedef NS_ENUM(NSInteger, TabBarPickerPosition) {
@property (nonatomic, readonly) CGFloat subItemHeight;
@property (nonatomic) BOOL dimWhenShow;
@property (nonatomic, strong) UIColor * dimColor;
@property (nonatomic, assign) id<TabBarPickerDelegate> delegate;
@property (nonatomic, strong,readonly) NSMutableDictionary *filtersEnabled;
/**
* Init TabBarPicker with items. When is selected an item the picher show down subitems.
+171 -41
View File
@@ -10,10 +10,12 @@
#import <PureLayout/PureLayout.h>
#import "TabBarPickerSubItemsView.h"
#import "MMCPSScrollView.h"
#import <UIView-Overlay/UIView+Overlay.h>
#import "NSString+HexColor.h"
#import <QuartzCore/QuartzCore.h>
@interface TabBarPicker() <TabBarPickerSubItemsViewDelegate,TabBarItemDelegate>
#define SUPERVIEW_TAG -9999
@interface TabBarPicker() <TabBarPickerSubItemsViewDelegate,TabBarItemDelegate,MMCPSScrollViewDelegate>
@property (nonatomic) UIDeviceOrientation orientation;
@property (nonatomic, strong) NSMutableArray *subItemSelectors;
@@ -25,9 +27,15 @@
@property (nonatomic, strong) NSMutableArray *tabBarItemsConstraints;
@property (nonatomic, strong) TabBarItem *selectedTabBarItem;
@property (nonatomic, strong) UIView *separator;
@property (nonatomic, strong) UIView *tabBarView;
@property (nonatomic, strong) MMCPSScrollView *subItemScrollView;
@property (nonatomic, strong) UIView* dimView;
@end
@implementation TabBarPicker
@@ -49,6 +57,8 @@
self = [self initForAutoLayout];
if (self) {
[self setUserInteractionEnabled:YES];
_filtersEnabled = [[NSMutableDictionary alloc] init];
_itemSpacing = 10;
_layoutRelation = relation;
_position = position;
@@ -58,6 +68,10 @@
_subItemSelectorsConstraints = [[NSMutableArray alloc] init];
_dimColor = [[@"333333" colorFromHex] colorWithAlphaComponent: 0.5];
_dimView = [UIView newAutoLayoutView];
[_dimView setAlpha:0];
[_dimView setBackgroundColor:_dimColor];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object: nil];
@@ -70,14 +84,19 @@
_tabBarItems = [[NSMutableArray alloc] init];
_tabBarView = [[UIView alloc] initForAutoLayout];
_tabBarView = [UIView newAutoLayoutView];
_separator = [UIView newAutoLayoutView];
[_separator.layer setMasksToBounds:NO];
[_separator setBackgroundColor:[[UIColor lightGrayColor] colorWithAlphaComponent:0.3]];
[self addSubview:_tabBarView];
for (NSObject *item in items) {
if (item && [item isKindOfClass:[TabBarItem class]]) {
TabBarItem *_item = (TabBarItem*)item;
[_item setTag:SUPERVIEW_TAG];;
[_tabBarItems addObject:_item];
[(TabBarItem*)_item setDelegate:self];
@@ -85,7 +104,7 @@
}
}
_subItemScrollView = [[MMCPSScrollView alloc] initForAutoLayout];
_subItemScrollView = [MMCPSScrollView newAutoLayoutView];
[_subItemScrollView setPagingEnabled:YES];
[_subItemScrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[_subItemScrollView setUserInteractionEnabled:YES];
@@ -93,6 +112,12 @@
[_subItemScrollView setPageSize:1];
[self addSubview:_subItemScrollView];
[self addSubview:_tabBarView];
[self addSubview:_separator];
[self setTag:SUPERVIEW_TAG];
}
[self updateConstraintsIfNeeded];
@@ -103,6 +128,14 @@
- (void) layoutSubviews {
if (!_didSetupConstraints) {
if (self.superview) {
[self.superview insertSubview:_dimView belowSubview:self];
[_dimView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview];
[_dimView autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self.superview];
[_dimView autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.superview];
[_dimView autoAlignAxis:ALAxisVertical toSameAxisOfView:self.superview];
}
switch (_position) {
case TabBarPickerPositionLeft:{
@@ -160,6 +193,10 @@
[_tabBarView autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_tabBarView autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self];
[_separator autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview];
[_separator autoSetDimension:ALDimensionHeight toSize:1];
[_separator autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:_tabBarView];
[_tabBarItems autoSetViewsDimension:ALDimensionHeight toSize:44.0];
[[_tabBarItems firstObject] autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
@@ -174,36 +211,13 @@
[_subItemScrollView setType:MMCPSScrollHorizontal];
if ([_tabBarItems count] > 0) {
int i = 0;
for (TabBarItem *item in _tabBarItems) {
if ([item itemSubView]) {
[item setTag:SUPERVIEW_TAG];
[[item itemSubView] setDelegate:self];
[[item itemSubView] setTabBarItemReference:self];
switch (i) {
case 0:
[[item itemSubView] setBackgroundColor:[UIColor lightGrayColor]];
break;
case 1:{
[[item itemSubView] setBackgroundColor:[UIColor redColor]];
}
break;
case 2:{
[[item itemSubView] setBackgroundColor:[UIColor greenColor]];
}
break;
case 3: {
[[item itemSubView] setBackgroundColor:[UIColor yellowColor]];
}
break;
default:{
[[item itemSubView] setBackgroundColor:[UIColor blueColor]];
}
break;
}
i++;
[[item itemSubView] setTabBarItemReference:item];
[_subItemScrollView addSubview:[item itemSubView]];
[_subItemSelectors addObject:[item itemSubView]];
@@ -221,11 +235,21 @@
}
_didSetupConstraints = YES;
[self updateConstraintsIfNeeded];
}
}
- (void) setTag:(NSInteger)tag {
[super setTag:tag];
for (UIView *subView in self.subviews) {
[subView setTag:tag];
}
for (UIView *subView in _subItemScrollView.subviews) {
[subView setTag:tag];
}
}
- (void) setPosition:(TabBarPickerPosition)position {
_position = position;
@@ -239,6 +263,7 @@
_orientation = [[UIDevice currentDevice] orientation];
}
- (void) addItem:(TabBarItem*) item {
if (item && [item isKindOfClass:[TabBarItem class]]) {
@@ -275,9 +300,10 @@
options:0
animations:^{
if (_dimWhenShow) {
[self.superview ag_addOverlayWithColor:_dimColor];
self.layer.zPosition = 999;
//[self.superview insertSubview:_dimView belowSubview:self];
[_dimView setAlpha:1];
//[self.superview ag_addOverlayWithColor:_dimColor];
//self.layer.zPosition = 999;
}
switch (_position) {
case TabBarPickerPositionLeft: {
@@ -325,8 +351,10 @@
options:0
animations:^{
if (_dimWhenShow) {
[self.superview ag_removeOverlay];
self.layer.zPosition = 0;
//[self.superview ag_removeOverlay];
//self.layer.zPosition = 0;
[_dimView setAlpha:0];
}
switch (_position) {
case TabBarPickerPositionLeft: {
@@ -350,21 +378,82 @@
break;
}
}
[_selectedTabBarItem setHighlighted:NO];
_selectedTabBarItem = nil;
[self layoutIfNeeded];
}
completion:^(BOOL finished) {
// Run the animation again in the other direction
//[_dimView removeFromSuperview];
}];
}
}
#pragma mark TabBarPickerSubItemsViewDelegate
- (void) tabarPickerSubItemsView:(TabBarPickerSubItemsView*) tabarPickerSubItemsView didSelect:(TabBarItem*) item {
- (void) tabBarPickerSubItemsView:(TabBarPickerSubItemsView*) tabBarPickerSubItemsView didSelectTabBarSubItem:(TabBarSubItem*) subItem forTabBarItem:(TabBarItem*) item {
switch (tabBarPickerSubItemsView.type) {
case TabBarPickerSubItemsViewTypeDistance: {
[_filtersEnabled setObject:subItem forKey:[item itemSearchKey]];
break;
}
case TabBarPickerSubItemsViewTypeDateAndTime: {
[_filtersEnabled setObject:subItem forKey:[item itemSearchKey]];
break;
}
case TabBarPickerSubItemsViewTypePrice: {
[_filtersEnabled setObject:subItem forKey:[item itemSearchKey]];
break;
}
case TabBarPickerSubItemsViewTypeCheckBox: {
[_filtersEnabled setObject:subItem forKey:[item itemSearchKey]];
break;
}
case TabBarPickerSubItemsViewTypeButton: {
[_filtersEnabled setObject:subItem forKey:[item itemSearchKey]];
break;
}
default: {
break;
}
}
if (_delegate && [_delegate respondsToSelector:@selector(TabBarPicker:filtersDidChanges:)]) {
[_delegate TabBarPicker:self filtersDidChanges:_filtersEnabled];
}
}
- (void) tabBarPickerSubItemsView:(TabBarPickerSubItemsView*) tabBarPickerSubItemsView didSelectTabBarSubItems:(NSArray*) subItems forTabBarItem:(TabBarItem*) item {
[_filtersEnabled setObject:subItems forKey:[item itemSearchKey]];
if (_delegate && [_delegate respondsToSelector:@selector(TabBarPicker:filtersDidChanges:)]) {
[_delegate TabBarPicker:self filtersDidChanges:_filtersEnabled];
}
}
- (void) tabBarPickerSubItemsView:(TabBarPickerSubItemsView*) tabBarPickerSubItemsView didResetTabBarSubItem:(TabBarSubItem *)subItem forTabBarItem:(TabBarItem *)item {
[_filtersEnabled removeObjectForKey:[item itemSearchKey]];
if (_delegate && [_delegate respondsToSelector:@selector(TabBarPicker:filtersDidChanges:)]) {
[_delegate TabBarPicker:self filtersDidChanges:_filtersEnabled];
}
}
- (void) tabBarPickerSubItemsView:(TabBarPickerSubItemsView*) tabBarPickerSubItemsView didResetTabBarSubItems:(NSArray*) subItems forTabBarItem:(TabBarItem*) item {
[_filtersEnabled removeObjectForKey:[item itemSearchKey]];
if (_delegate && [_delegate respondsToSelector:@selector(TabBarPicker:filtersDidChanges:)]) {
[_delegate TabBarPicker:self filtersDidChanges:_filtersEnabled];
}
}
#pragma mark -
#pragma mark TabBarPickerSubItemsViewDataSource
#pragma mark -
#pragma mark TabBarItemDelegate
@@ -394,13 +483,54 @@
#pragma mark MMCPSScrollViewDelegate
- (void)scrollView:(MMCPSScrollView *)scrollView didScrollToPage:(NSUInteger)pageIndex {
NSLog(@"The MMCPSScrollView is now on page %i.", pageIndex);
if ([scrollView currentPage] > 0 && [_tabBarItems count] > [scrollView currentPage]-1) {
TabBarItem *selectedItem = [_tabBarItems objectAtIndex:[scrollView currentPage]-1];
for (TabBarItem *item in _tabBarItems) {
if (![item isEqual:selectedItem]) {
[item setHighlighted:NO];
}
else {
[item setHighlighted:YES];
}
}
if (!_isShow) {
[self show];
}
else {
if(![_selectedTabBarItem isEqual:selectedItem]) {
}
}
_selectedTabBarItem = selectedItem;
}
}
- (void)scrollView:(MMCPSScrollView *)scrollView willScrollToPage:(NSUInteger)pageIndex {
NSLog(@"The MMCPSScrollView is now going to page %i.", pageIndex);
}
#pragma mark -
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (!self.isUserInteractionEnabled || self.isHidden || self.alpha <= 0.01) {
return nil;
}
if ([self pointInside:point withEvent:event]) {
for (UIView *subview in [self.subviews reverseObjectEnumerator]) {
CGPoint convertedPoint = [subview convertPoint:point fromView:self];
UIView *hitTestView = [subview hitTest:convertedPoint withEvent:event];
if (hitTestView) {
return hitTestView;
}
}
return self;
}
[self hide];
return nil;
}
@end
+25 -5
View File
@@ -14,17 +14,24 @@
typedef NS_ENUM(NSInteger, TabBarPickerSubItemsViewType) {
// Informational
TabBarPickerSubItemsViewTypeData,
TabBarPickerSubItemsViewTypeString,
TabBarPickerSubItemsViewTypeButtons,
TabBarPickerSubItemsViewTypeCheckBox
TabBarPickerSubItemsViewTypeDistance,
TabBarPickerSubItemsViewTypeDateAndTime,
TabBarPickerSubItemsViewTypePrice,
TabBarPickerSubItemsViewTypeCheckBox,
TabBarPickerSubItemsViewTypeButton
};
@protocol TabBarPickerSubItemsViewDelegate <NSObject>
@required
- (void) tabarPickerSubItemsView:(TabBarPickerSubItemsView*) tabarPickerSubItemsView didSelectTabBarSubItem:(TabBarSubItem*) subItem forTabBarItem:(TabBarItem*) item;
- (void) tabBarPickerSubItemsView:(TabBarPickerSubItemsView*) tabBarPickerSubItemsView didSelectTabBarSubItem:(TabBarSubItem*) subItem forTabBarItem:(TabBarItem*) item;
- (void) tabBarPickerSubItemsView:(TabBarPickerSubItemsView*) tabBarPickerSubItemsView didSelectTabBarSubItems:(NSArray*) subItems forTabBarItem:(TabBarItem*) item;
- (void) tabBarPickerSubItemsView:(TabBarPickerSubItemsView*) tabBarPickerSubItemsView didResetTabBarSubItem:(TabBarSubItem*) subItem forTabBarItem:(TabBarItem*) item;
- (void) tabBarPickerSubItemsView:(TabBarPickerSubItemsView*) tabBarPickerSubItemsView didResetTabBarSubItems:(NSArray*) subItems forTabBarItem:(TabBarItem*) item;
@end
@@ -45,10 +52,23 @@ typedef NS_ENUM(NSInteger, TabBarPickerSubItemsViewType) {
/**
* <#Description#>
*/
@property (nonatomic, strong) TabBarItem *tabBarItemReference;
@property (nonatomic,readonly) TabBarPickerSubItemsViewType type;
@property (nonatomic, strong, readonly) NSDate *pickerSelectedDate;
@property (nonatomic, strong, readonly) TabBarSubItem *selectedDate;
@property (nonatomic, strong, readonly) TabBarSubItem *selectedDistance;
@property (nonatomic, strong, readonly) TabBarSubItem *selectedMinPrice;
@property (nonatomic, strong, readonly) TabBarSubItem *selectedMaxPrice;
@property (nonatomic, strong, readonly) NSMutableArray *selectedAllergens;
@property (nonatomic, strong, readonly) NSMutableArray *selectedTypes;
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type subItems:(NSArray*) subItems;
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type subItems:(NSArray*) subItems needsLocalization:(BOOL) needsLocalization;
- (void) setItemName:(NSString *) itemName;
@end
+617 -25
View File
@@ -12,17 +12,34 @@
#import "NSString+HexColor.h"
#import "SharedLocationManager.h"
#import "UIAlertView+BlockExtension.h"
#import "AADatePicker.h"
#import "ToucheableScrollView.h"
@interface TabBarPickerSubItemsView()
@interface TabBarPickerSubItemsView() <UIPickerViewDataSource,UIPickerViewDelegate,AADatePickerDelegate,TabBarSubItemDelegate>
@property (nonatomic, assign) BOOL didSetupConstraints;
@property (nonatomic) TabBarPickerSubItemsViewType type;
@property (nonatomic, strong) NSMutableArray *subItems;
@property (nonatomic, strong) UIView *switchBarView;
@property (nonatomic, strong) UISwitch *itemSwich;
@property (nonatomic, strong) UILabel *switchBarLabel;
@property (nonatomic, strong) UIButton *localizationButton;
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) UIView *HUD;
@property (nonatomic, strong) UIPickerView *pickerView;
@property (nonatomic, strong) AADatePicker *datePicker;
@property (nonatomic, strong) ToucheableScrollView *scrollView;
@property (nonatomic, strong) UILabel *minPrice;
@property (nonatomic, strong) UILabel *maxPrice;
@property (nonatomic) NSUInteger firstLoadFirstComponent;
@property (nonatomic) NSUInteger firstLoadSecondComponent;
@end
@@ -34,21 +51,35 @@
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type subItems:(NSArray*) subItems needsLocalization:(BOOL) needsLocalization{
self = [self initForAutoLayout];
self = [self initForAutoLayout];
if (self) {
_firstLoadFirstComponent = 0;
_firstLoadSecondComponent = 0;
_selectedAllergens = [[NSMutableArray alloc] init];
_selectedTypes = [[NSMutableArray alloc] init];
[self setUserInteractionEnabled:YES];
[self setBackgroundColor:[UIColor whiteColor]];
_type = type;
_subItems = [[NSMutableArray alloc] init];
for (NSObject *subItem in subItems) {
if ([subItem isKindOfClass:[TabBarSubItem class]]) {
[(TabBarSubItem*)subItem setType:(TabBarSubItemsViewType)_type];
[_subItems addObject:subItem];
}
}
_needsLocalization = needsLocalization;
_switchBarView = [[UIView alloc] initForAutoLayout];
_switchBarView = [UIView newAutoLayoutView];
[_switchBarView setBackgroundColor:[@"f7f7f7" colorFromHex]];
_switchBarLabel = [[UILabel alloc] initForAutoLayout];
_switchBarLabel = [UILabel newAutoLayoutView];
[_switchBarLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:14]];
[_switchBarLabel setTextColor:[@"999999" colorFromHex]];
[_switchBarLabel setText:NSLocalizedString(@"Distance", @"")];
[_switchBarView addSubview:_switchBarLabel];
_itemSwich = [[UISwitch alloc] initForAutoLayout];
_itemSwich = [UISwitch newAutoLayoutView];
[_itemSwich setOnTintColor:[@"ff4e50" colorFromHex]];
[_itemSwich.layer setBorderWidth:2];
@@ -57,26 +88,81 @@
[_itemSwich setUserInteractionEnabled:YES];
[_itemSwich addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged];
_contentView = [[UIView alloc] initForAutoLayout];
_contentView = [UIView newAutoLayoutView];
[self addSubview:_contentView];
switch (_type) {
case TabBarPickerSubItemsViewTypeDateAndTime: {
_datePicker = [AADatePicker newAutoLayoutView];
[_datePicker setShowOnlyValidDates:YES];
[_datePicker setDelegate:self];
[_contentView addSubview:_datePicker];
break;
}
case TabBarPickerSubItemsViewTypeDistance:{
_pickerView = [UIPickerView newAutoLayoutView];
[_pickerView setDelegate:self];
[_pickerView setDataSource:self];
[_contentView addSubview:_pickerView];
break;
}
case TabBarPickerSubItemsViewTypePrice: {
_pickerView = [UIPickerView newAutoLayoutView];
[_pickerView setDelegate:self];
[_pickerView setDataSource:self];
[_contentView addSubview:_pickerView];
_minPrice = [UILabel newAutoLayoutView];
[_minPrice setTextAlignment:NSTextAlignmentCenter];
[_minPrice setText:NSLocalizedString(@"KEY_FILTER_PRICE_MIN", @"")];
[_minPrice setFont:[UIFont fontWithName:@"HelveticaNeue" size:10]];
[_minPrice setTextColor:[@"999999" colorFromHex]];
[_contentView addSubview:_minPrice];
_maxPrice = [UILabel newAutoLayoutView];
[_maxPrice setTextAlignment:NSTextAlignmentCenter];
[_maxPrice setText:NSLocalizedString(@"KEY_FILTER_PRICE_MAX", @"")];
[_maxPrice setFont:[UIFont fontWithName:@"HelveticaNeue" size:10]];
[_maxPrice setTextColor:[@"999999" colorFromHex]];
[_contentView addSubview:_maxPrice];
break;
}
case TabBarPickerSubItemsViewTypeCheckBox:
case TabBarPickerSubItemsViewTypeButton:{
_scrollView = [ToucheableScrollView newAutoLayoutView];
[_scrollView setBackgroundColor:[UIColor clearColor]];
for (TabBarSubItem *item in _subItems) {
[item setDelegate:self];
[_scrollView addSubview:item];
}
[_contentView addSubview:_scrollView];
break;
}
default: {
break;
}
}
if (_needsLocalization) {
_localizationView = [[UIView alloc] initForAutoLayout];
[_localizationView setBackgroundColor:[UIColor purpleColor]];
_localizationView = [UIView newAutoLayoutView];
[_localizationView setBackgroundColor:[UIColor whiteColor]];
[_localizationView setAlpha:0];
_localizationButton = [[UIButton alloc] initForAutoLayout];
_localizationButton = [UIButton newAutoLayoutView];
[_localizationButton setTitle:NSLocalizedString(@"ATTIVA LOCALIZZAZIONE DISPOSITIVO", @"") forState:UIControlStateNormal];
[_localizationButton addTarget:self action:@selector(openSettings) forControlEvents:UIControlEventTouchUpInside];
[_localizationButton setBackgroundColor:[UIColor whiteColor]];
[_localizationButton.layer setBorderColor:[[@"ff4e50" colorFromHex] CGColor]];
[_localizationButton.layer setBorderWidth:1];
[_localizationButton setTitleColor:[@"ff4e50" colorFromHex] forState:UIControlStateNormal];
[_localizationButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[_localizationButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:14]];
[_localizationButton.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:14]];
[_localizationButton setContentEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 10)];
[_localizationView addSubview:_localizationButton];
@@ -86,6 +172,11 @@
[self addSubview:_switchBarView];
[_switchBarView addSubview:_itemSwich];
_HUD = [UIView newAutoLayoutView];
[_HUD setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.25]];
[_HUD setAlpha:1];
[_contentView addSubview:_HUD];
}
[self updateConstraintsIfNeeded];
@@ -93,12 +184,34 @@
return self;
}
- (void) setTag:(NSInteger)tag {
[super setTag:tag];
for (UIView *subView in self.subviews) {
[subView setTag:tag];
}
[_HUD setTag:tag];
[_localizationButton setTag:tag];
[_localizationView setTag:tag];
}
- (void) layoutSubviews {
[UIView animateWithDuration:0.5 animations:^{
[_localizationView setAlpha:[[NSNumber numberWithBool:[[SharedLocationManager sharedManager] localizationIsAuthorized]] floatValue]];
}];
//NSAssert(_dataSource, @"TabBarPickerSubItemsView needs datasource");
if (_needsLocalization) {
[UIView animateWithDuration:0.5 animations:^{
[_localizationView setAlpha:[[NSNumber numberWithBool:![[SharedLocationManager sharedManager] localizationIsAuthorized]] floatValue]];
if ([[SharedLocationManager sharedManager] localizationIsAuthorized]) {
[_itemSwich setUserInteractionEnabled:YES];
}
else {
[_itemSwich setUserInteractionEnabled:NO];
[_itemSwich setOn:NO];
}
}];
}
if (!_didSetupConstraints) {
@@ -121,23 +234,138 @@
[_contentView autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self];
[_contentView autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_HUD autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:_contentView];
[_HUD autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:_contentView];
[_HUD autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_HUD autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:_contentView];
switch (_type) {
case TabBarPickerSubItemsViewTypeDateAndTime: {
[_datePicker autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:_contentView];
[_datePicker autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_datePicker autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
break;
}
case TabBarPickerSubItemsViewTypeDistance:{
[_pickerView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:_contentView];
[_pickerView autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_pickerView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
break;
}
case TabBarPickerSubItemsViewTypePrice: {
[_minPrice autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:_switchBarView withOffset:10];
[_minPrice autoSetDimension:ALDimensionWidth toSize:[[UIScreen mainScreen] bounds].size.width/2];
[_minPrice autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:_contentView];
[_maxPrice autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:_switchBarView withOffset:10];
[_maxPrice autoSetDimension:ALDimensionWidth toSize:[[UIScreen mainScreen] bounds].size.width/2];
[_maxPrice autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:_contentView];
[_pickerView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:_contentView];
[_pickerView autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_pickerView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
break;
}
case TabBarPickerSubItemsViewTypeButton:{
[_scrollView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:_contentView];
[_scrollView autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_scrollView autoPinEdgeToSuperviewEdge:ALEdgeTop];
[_scrollView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:40];
//[_subItems autoDistributeViewsAlongAxis:ALAxisVertical alignedTo:ALAttributeVertical withFixedSpacing:10 insetSpacing:YES matchedSizes:YES];
//[[_subItems firstObject] autoAlignAxisToSuperviewAxis:ALAxisVertical];
BOOL firstOfRow = YES;
TabBarSubItem *prevItem;
CGFloat currentWidth = 0;
for (TabBarSubItem *item in _subItems) {
if (currentWidth + item.subItemSize.width > [[UIScreen mainScreen] bounds].size.width) {
firstOfRow = YES;
currentWidth = 0;
}
if (firstOfRow) {
if (prevItem) {
[item autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:prevItem withOffset:0];
}
else {
[item autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:_scrollView withOffset:0];
}
[item autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:_scrollView withOffset:0];
prevItem = item;
firstOfRow = NO;
}
else {
[item autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:prevItem withOffset:0];
[item autoAlignAxis:ALAxisHorizontal toSameAxisOfView:prevItem withOffset:0];
prevItem = item;
if ([item isEqual:[_subItems lastObject]]) {
[item autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:_scrollView withOffset:0];
}
}
currentWidth += item.subItemSize.width;
}
break;
}
case TabBarPickerSubItemsViewTypeCheckBox: {
[_scrollView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:_contentView];
[_scrollView autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_scrollView autoPinEdgeToSuperviewEdge:ALEdgeTop];
[_scrollView autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:40];
TabBarSubItem *prevItem;
BOOL firstOfRow = YES;
for (TabBarSubItem *item in _subItems) {
if (firstOfRow) {
if (prevItem) {
[item autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:prevItem withOffset:0];
}
else {
[item autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:_scrollView withOffset:0];
}
[item autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:_scrollView withOffset:0];
firstOfRow = NO;
prevItem = item;
}
else {
[item autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:prevItem withOffset:0];
[item autoAlignAxis:ALAxisHorizontal toSameAxisOfView:prevItem withOffset:0];
firstOfRow = YES;
if ([item isEqual:[_subItems lastObject]]) {
[item autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:_scrollView withOffset:0];
[prevItem autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:_scrollView withOffset:0];
}
}
}
break;
}
default: {
break;
}
}
if (_needsLocalization) {
[_localizationView autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:_contentView];
[_localizationView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:_contentView];
[_localizationView autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
[_localizationView autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_localizationButton autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
[_localizationButton autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_localizationButton autoSetDimension:ALDimensionHeight toSize:44 relation:NSLayoutRelationLessThanOrEqual];
[_localizationButton autoSetDimension:ALDimensionHeight toSize:44 relation:NSLayoutRelationEqual];
[_localizationButton autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self withMultiplier:0.8];
[_localizationButton.layer setCornerRadius:44/2];
}
_didSetupConstraints = YES;
}
[_localizationButton.layer setCornerRadius:_localizationButton.frame.size.height/2];
}
- (void) setBackgroundColor:(UIColor *)backgroundColor {
@@ -151,12 +379,24 @@
[self addSubview:_localizationView];
}
- (void)openSettings
- (void) dateChanged:(AADatePicker *)datePicker {
_pickerSelectedDate = datePicker.date;
_selectedDate = [TabBarSubItem tabBarSubItemWithName:@"date" firstValue:_pickerSelectedDate secondValue:nil andReference:_pickerSelectedDate];
[_selectedDate setType:(TabBarSubItemsViewType)_type];
[_tabBarItemReference setSelected:YES];
if (_selectedDate) {
if (_delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didSelectTabBarSubItem:forTabBarItem:)]) {
[_delegate tabBarPickerSubItemsView:self didSelectTabBarSubItem:_selectedDate forTabBarItem:_tabBarItemReference];
}
}
}
- (void) openSettings
{
UIAlertView *alert = [UIAlertView alertViewWithTitle:NSLocalizedString(@"Settings", @"") message:NSLocalizedString(@"Open Settings?", @"")];
[alert addButtonWithTitle:NSLocalizedString(@"OK", @"") actionBlock:^(UIAlertView *alertView, NSInteger buttonIndex) {
[alert addButtonWithTitle:NSLocalizedString(@"KEY_OK", @"") actionBlock:^(UIAlertView *alertView, NSInteger buttonIndex) {
NSURL *settings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:settings])
{
@@ -170,12 +410,152 @@
- (void)changeSwitch:(UISwitch*)sender{
[_HUD setAlpha:[[NSNumber numberWithBool:![sender isOn]] floatValue]];
if([sender isOn]){
NSLog(@"Switch is ON");
switch (_type) {
case TabBarPickerSubItemsViewTypeDistance: {
if (!_selectedDistance) {
_selectedDistance = [_subItems objectAtIndex:[_pickerView selectedRowInComponent:0]];
[_tabBarItemReference setSelected:YES];
}
if (_delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didSelectTabBarSubItem:forTabBarItem:)]) {
[_delegate tabBarPickerSubItemsView:self didSelectTabBarSubItem:_selectedDistance forTabBarItem:_tabBarItemReference];
}
break;
}
case TabBarPickerSubItemsViewTypeDateAndTime: {
if (_selectedDate) {
if (_delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didSelectTabBarSubItem:forTabBarItem:)]) {
[_delegate tabBarPickerSubItemsView:self didSelectTabBarSubItem:_selectedDate forTabBarItem:_tabBarItemReference];
}
}
break;
}
case TabBarPickerSubItemsViewTypePrice: {
if ([_subItems count] > 0) {
if (!_selectedMinPrice) {
_selectedMinPrice = [_subItems objectAtIndex:[_pickerView selectedRowInComponent:0]];
}
if (!_selectedMaxPrice) {
_selectedMaxPrice = [_subItems objectAtIndex:[_pickerView selectedRowInComponent:1]];
}
if ((_selectedMaxPrice || _selectedMinPrice) && _delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didSelectTabBarSubItems:forTabBarItem:)]) {
//[_delegate tabBarPickerSubItemsView:self didSelectTabBarSubItem:_selectedMinPrice forTabBarItem:_tabBarItemReference];
[_tabBarItemReference setSelected:YES];
[_delegate tabBarPickerSubItemsView:self didSelectTabBarSubItems:@[_selectedMinPrice,_selectedMaxPrice] forTabBarItem:_tabBarItemReference];
}
}
else {
[_tabBarItemReference setSelected:NO];
}
break;
}
case TabBarPickerSubItemsViewTypeCheckBox: {
if ([_selectedTypes count] > 0 && _delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didSelectTabBarSubItems:forTabBarItem:)]) {
//[_delegate tabBarPickerSubItemsView:self didSelectTabBarSubItem:_selectedMinPrice forTabBarItem:_tabBarItemReference];
[_delegate tabBarPickerSubItemsView:self didSelectTabBarSubItems:_selectedTypes forTabBarItem:_tabBarItemReference];
}
break;
}
case TabBarPickerSubItemsViewTypeButton: {
if ([_selectedTypes count] > 0 && _delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didSelectTabBarSubItems:forTabBarItem:)]) {
//[_delegate tabBarPickerSubItemsView:self didSelectTabBarSubItem:_selectedMinPrice forTabBarItem:_tabBarItemReference];
[_delegate tabBarPickerSubItemsView:self didSelectTabBarSubItems:_selectedAllergens forTabBarItem:_tabBarItemReference];
}
break;
}
default: {
break;
}
}
} else{
NSLog(@"Switch is OFF");
switch (_type) {
case TabBarPickerSubItemsViewTypeDistance: {
_selectedDistance = nil;
[_pickerView selectRow:0 inComponent:0 animated:YES];
[self pickerView:_pickerView didSelectRow:0 inComponent:0];
if (_delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didResetTabBarSubItem:forTabBarItem:)]) {
[_delegate tabBarPickerSubItemsView:self didResetTabBarSubItem:_selectedDistance forTabBarItem:_tabBarItemReference];
}
break;
}
case TabBarPickerSubItemsViewTypeDateAndTime: {
_selectedDate = nil;
[_datePicker resetPicker];
if (_delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didResetTabBarSubItem:forTabBarItem:)]) {
[_delegate tabBarPickerSubItemsView:self didResetTabBarSubItem:_selectedDate forTabBarItem:_tabBarItemReference];
}
break;
}
case TabBarPickerSubItemsViewTypePrice: {
_selectedMinPrice = nil;
_selectedMaxPrice = nil;
if ([_subItems count] > 0) {
[_pickerView selectRow:0 inComponent:0 animated:YES];
[_pickerView selectRow:0 inComponent:1 animated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self pickerView:_pickerView didSelectRow:0 inComponent:0 update:NO];
[self pickerView:_pickerView didSelectRow:0 inComponent:1 update:NO];
[[self tabBarItemReference] setSelected:NO];
});
if (_selectedMinPrice && _selectedMaxPrice) {
if (_delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didResetTabBarSubItems:forTabBarItem:)]) {
[_delegate tabBarPickerSubItemsView:self didResetTabBarSubItems:@[_selectedMinPrice,_selectedMaxPrice] forTabBarItem:_tabBarItemReference];
}
}
else {
if (_delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didResetTabBarSubItems:forTabBarItem:)]) {
[_delegate tabBarPickerSubItemsView:self didResetTabBarSubItems:nil forTabBarItem:_tabBarItemReference];
}
}
}
break;
}
case TabBarPickerSubItemsViewTypeCheckBox: {
for (TabBarSubItem* selectedType in _selectedTypes) {
[selectedType setSelected:NO];
}
[_selectedTypes removeAllObjects];
if (_delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didResetTabBarSubItems:forTabBarItem:)]) {
[_delegate tabBarPickerSubItemsView:self didResetTabBarSubItems:_selectedTypes forTabBarItem:_tabBarItemReference];
}
break;
}
case TabBarPickerSubItemsViewTypeButton: {
for (TabBarSubItem* selectedAllergen in _selectedAllergens) {
[selectedAllergen setSelected:NO];
}
[_selectedAllergens removeAllObjects];
if (_delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didResetTabBarSubItems:forTabBarItem:)]) {
[_delegate tabBarPickerSubItemsView:self didResetTabBarSubItems:_selectedAllergens forTabBarItem:_tabBarItemReference];
}
break;
}
default: {
break;
}
}
[_tabBarItemReference setSelected:NO];
}
}
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
@@ -188,4 +568,216 @@
[super touchesBegan: touches withEvent:event];
}
- (void) setItemName:(NSString *) itemName {
[_switchBarLabel setText:itemName];
}
#pragma mark UIPickerViewDataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
if ([_subItems count] > 0) {
return [(TabBarSubItem*)[_subItems firstObject] numberOfValues];
//return [_subItems count];
}
return 0;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [_subItems count];
}
#pragma mark -
#pragma mark UIPickerViewDelegate
/*- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
}*/
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
NSString *string;
TabBarSubItem *subItem = [_subItems objectAtIndex:row];
switch (_type) {
case TabBarPickerSubItemsViewTypeDistance: {
string = [subItem name];
break;
}
case TabBarPickerSubItemsViewTypePrice: {
string = [subItem getValueForPrice:component];
/*if (component == 1 && [subItem isEqual:[_subItems objectAtIndex:[_subItems count]-1]]) {
string = [@"" stringByAppendingString:string];
}*/
break;
}
default: {
break;
}
}
NSDictionary *attributeDict;
if ((_firstLoadFirstComponent == 0 && component == 0) || ((_firstLoadSecondComponent == 0 && component == 1))) {
attributeDict = @{NSForegroundColorAttributeName : [@"ff4e50" colorFromHex],NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue" size:23]};
if ((_firstLoadFirstComponent == 0 && component == 0)) {
_firstLoadFirstComponent++;
}
else {
_firstLoadSecondComponent++;
}
}
else {
attributeDict = @{NSForegroundColorAttributeName : [@"999999" colorFromHex],NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue" size:16]};
}
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:string attributes:attributeDict];
// add the string to a label's attributedText property
UILabel *labelView = [[UILabel alloc] init];
[labelView setTextAlignment:NSTextAlignmentCenter];
labelView.attributedText = attributedString;
// return the label
return labelView;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
return 74;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
[self pickerView:pickerView didSelectRow:row inComponent:component update:YES];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component update:(BOOL) update {
[_tabBarItemReference setSelected:YES];
UILabel *labelSelected = (UILabel*)[pickerView viewForRow:row forComponent:component];
if (labelSelected) {
NSDictionary *attributeDict = @{NSForegroundColorAttributeName : [@"ff4e50" colorFromHex],NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue" size:23]};
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:labelSelected.text attributes:attributeDict];
[labelSelected setAttributedText:attributedString];
}
switch (_type) {
case TabBarPickerSubItemsViewTypeDistance: {
_selectedDistance = [_subItems objectAtIndex:row];
if (update) {
if (_delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didSelectTabBarSubItems:forTabBarItem:)]) {
[_delegate tabBarPickerSubItemsView:self didSelectTabBarSubItem:_selectedDistance forTabBarItem:_tabBarItemReference];
}
}
break;
}
case TabBarPickerSubItemsViewTypePrice: {
switch (component) {
case 0:{
if ([pickerView selectedRowInComponent:1] < row) {
[pickerView selectRow:row inComponent:1 animated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self pickerView:pickerView didSelectRow:row inComponent:1 update:NO];
});
}
_selectedMinPrice = [_subItems objectAtIndex:row];
_selectedMaxPrice = [_subItems objectAtIndex:row];
break;
}
default:{
if ([pickerView selectedRowInComponent:0] > row) {
[pickerView selectRow:row inComponent:0 animated:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self pickerView:pickerView didSelectRow:row inComponent:0 update:NO];
});
}
_selectedMinPrice = [_subItems objectAtIndex:row];
_selectedMaxPrice = [_subItems objectAtIndex:row];
break;
}
}
if (!_selectedMinPrice) {
_selectedMinPrice = [_subItems objectAtIndex:[_pickerView selectedRowInComponent:0]];
}
if (!_selectedMaxPrice) {
_selectedMaxPrice = [_subItems objectAtIndex:[_pickerView selectedRowInComponent:1]];
}
if (update) {
if (_delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didSelectTabBarSubItems:forTabBarItem:)]) {
[_delegate tabBarPickerSubItemsView:self didSelectTabBarSubItems:@[_selectedMinPrice,_selectedMaxPrice] forTabBarItem:_tabBarItemReference];
}
}
break;
}
default: {
break;
}
}
}
#pragma mark -
#pragma mark TabBarSubItemDelegate
- (void) tabBarSubItem:(TabBarSubItem*) item didSelected:(BOOL) selected {
NSMutableArray *refArray;
switch (_type) {
case TabBarPickerSubItemsViewTypeCheckBox: {
refArray = _selectedTypes;
break;
}
case TabBarPickerSubItemsViewTypeButton: {
refArray = _selectedAllergens;
break;
}
default: {
break;
}
}
if (selected) {
if (![refArray containsObject:item]) {
[refArray addObject:item];
}
}
else {
if ([refArray containsObject:item]) {
[refArray removeObject:item];
}
}
if ([refArray count] > 0) {
[_tabBarItemReference setSelected:YES];
}
else {
[_tabBarItemReference setSelected:NO];
}
if (_delegate && [_delegate respondsToSelector:@selector(tabBarPickerSubItemsView:didSelectTabBarSubItems:forTabBarItem:)]) {
//[_delegate tabBarPickerSubItemsView:self didSelectTabBarSubItem:_selectedMinPrice forTabBarItem:_tabBarItemReference];
[_delegate tabBarPickerSubItemsView:self didSelectTabBarSubItems:refArray forTabBarItem:_tabBarItemReference];
}
}
#pragma mark -
@end
+41 -2
View File
@@ -8,12 +8,51 @@
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, TabBarSubItemsViewType) {
TabBarSubItemsViewTypeDistance,
TabBarSubItemsViewTypeDateAndTime,
TabBarSubItemsViewTypePrice,
TabBarSubItemsViewTypeCheckBox,
TabBarSubItemsViewTypeButton,
};
@class TabBarSubItem;
@protocol TabBarSubItemDelegate <NSObject>
@required
- (void) tabBarSubItem:(TabBarSubItem*) item didSelected:(BOOL) selected;
@end
@interface TabBarSubItem : UIView
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) UIButton *subItemButton;
@property (nonatomic, strong) id value;
@property (nonatomic, strong) id firstValue;
@property (nonatomic, strong) id secondValue;
@property (nonatomic, strong) id objectReference;
@property (nonatomic, readonly) CGSize subItemSize;
@property (nonatomic) TabBarSubItemsViewType type;
@property (nonatomic) BOOL isLast;
+ (instancetype) tabBarSubItemWithName:(NSString*)name andValue:(id) value;;
@property (nonatomic, strong) id<TabBarSubItemDelegate> delegate;
+ (instancetype) tabBarSubItemWithName:(NSString*) name value:(id) value andReference:(id)reference;
+ (instancetype) tabBarSubItemWithName:(NSString*) name value:(id) value andReference:(id)reference forType:(TabBarSubItemsViewType) type;
+ (instancetype) tabBarSubItemWithName:(NSString *) name firstValue:(id)firstValue secondValue:(id) secondValue andReference:(id) reference;
+ (instancetype) tabBarSubItemWithName:(NSString *) name firstValue:(id)firstValue secondValue:(id) secondValue andReference:(id) reference forType:(TabBarSubItemsViewType) type;
- (NSUInteger) numberOfValues;
- (NSString *) getValueForPrice:(NSInteger) value;
- (void) setSelected:(BOOL) selected;
- (BOOL) isSelected;
@end
+152 -18
View File
@@ -8,34 +8,100 @@
#import "TabBarSubItem.h"
#import <PureLayout/PureLayout.h>
#import "NSString+HexColor.h"
@interface TabBarSubItem()
@property (nonatomic) UIDeviceOrientation orientation;
@property (nonatomic, assign) BOOL didSetupConstraints;
@property (nonatomic) CGFloat buttonCornerRadius;
@end
@implementation TabBarSubItem
- (instancetype) initWithName:(NSString *) name andValue:(id)value {
- (instancetype) initWithName:(NSString *) name firstValue:(id)firstValue secondValue:(id) secondValue reference:(id) reference forType:(TabBarSubItemsViewType) type {
self = [self initForAutoLayout];
if (self) {
//[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
_name = name;
_subItemButton = [[UIButton alloc] initForAutoLayout];
_type = type;
_subItemButton = [UIButton newAutoLayoutView];
[_subItemButton setTitle:_name forState:UIControlStateNormal];
_value = value;
[_subItemButton addTarget:self action:@selector(itemSelected:) forControlEvents:UIControlEventTouchUpInside];
[_subItemButton setBackgroundColor:[UIColor whiteColor]];
[_subItemButton setTitleColor:[@"999999" colorFromHex] forState:UIControlStateNormal];
[_subItemButton setTitleColor:[@"ff4e50" colorFromHex] forState:UIControlStateSelected];
switch (_type) {
case TabBarSubItemsViewTypeCheckBox: {
[_subItemButton.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:12]];
[_subItemButton setImage:[UIImage imageNamed:@"checkBox"] forState:UIControlStateNormal];
[_subItemButton setImage:[UIImage imageNamed:@"checkBoxSelected"] forState:UIControlStateSelected];
[_subItemButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
//CGFloat textWidth = [_subItemButton.currentTitle sizeWithAttributes:[_subItemButton.titleLabel.attributedText attributesAtIndex:0 effectiveRange:NULL]].width;
_subItemButton.imageEdgeInsets = UIEdgeInsetsMake(0, 22, 0, 0);
_subItemButton.titleEdgeInsets = UIEdgeInsetsMake(0, _subItemButton.imageView.frame.size.width + 10, 0, 0);
//[_subItemButton setContentEdgeInsets:UIEdgeInsetsMake(5, 15, 5, 15)];
_subItemSize = CGSizeMake([[UIScreen mainScreen] bounds].size.width/2, 66);
break;
}
case TabBarSubItemsViewTypeButton: {
[_subItemButton.layer setBorderColor:[[@"999999" colorFromHex] CGColor]];
[_subItemButton.layer setBorderWidth:1];
//[_subItemButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[_subItemButton.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:14]];
[_subItemButton setContentEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 10)];
CGSize size = [_subItemButton sizeThatFits:[[UIScreen mainScreen] bounds].size];
_buttonCornerRadius = size.height/2;
_subItemSize = size;
_subItemSize.width = _subItemSize.width + _subItemButton.contentEdgeInsets.left/2 + _subItemButton.contentEdgeInsets.right/2;
_subItemSize.height = _subItemSize.height+ _subItemButton.contentEdgeInsets.top + _subItemButton.contentEdgeInsets.bottom;
break;
}
default: {
break;
}
}
[self addSubview:_subItemButton];
_firstValue = ( firstValue ? firstValue : @"");
_objectReference = (reference ? reference : _firstValue);
_secondValue = secondValue;
}
[self updateConstraintsIfNeeded];
return self;
}
+ (instancetype) tabBarSubItemWithName:(NSString*)name andValue:(id)value {
return [[self alloc] initWithName:name andValue:value];
+ (instancetype) tabBarSubItemWithName:(NSString*)name value:(id) value andReference:(id)reference {
return [[self alloc] initWithName:name firstValue:value secondValue:nil reference:reference forType:TabBarSubItemsViewTypeButton];
}
+ (instancetype) tabBarSubItemWithName:(NSString*)name value:(id) value andReference:(id)reference forType:(TabBarSubItemsViewType) type {
return [[self alloc] initWithName:name firstValue:value secondValue:nil reference:reference forType:type];
}
+ (instancetype) tabBarSubItemWithName:(NSString *) name firstValue:(id)firstValue secondValue:(id) secondValue andReference:(id) reference {
return [[self alloc] initWithName:name firstValue:firstValue secondValue:secondValue reference:reference forType:TabBarSubItemsViewTypeButton];
}
+ (instancetype) tabBarSubItemWithName:(NSString *) name firstValue:(id)firstValue secondValue:(id) secondValue andReference:(id) reference forType:(TabBarSubItemsViewType) type {
return [[self alloc] initWithName:name firstValue:firstValue secondValue:secondValue reference:reference forType:type];
}
- (void) setName:(NSString *)name {
@@ -43,28 +109,96 @@
[_subItemButton setTitle:_name forState:UIControlStateNormal];
}
- (void)deviceOrientationDidChange:(NSNotification *)notification {
//Obtain current device orientation
_orientation = [[UIDevice currentDevice] orientation];
- (NSUInteger) numberOfValues {
NSUInteger response = 0;
[self layoutSubviews];
if (_firstValue) {
response++;
}
if (_secondValue) {
response++;
}
return response;
}
- (NSString *) getValueForPrice:(NSInteger) value {
NSString *responseString;
switch (value) {
case 0:
if ([_firstValue isKindOfClass:[NSString class]]) {
return _firstValue;
}
else {
responseString = [NSString stringWithFormat:@"%@ %00.02f",_name,[_firstValue floatValue]];
}
break;
default:{
if ([_secondValue isKindOfClass:[NSString class]]) {
return _secondValue;
}
else {
responseString = [NSString stringWithFormat:@"%@ %00.02f",_name,[_secondValue floatValue]];
}
}
break;
}
return responseString;
}
- (void) layoutSubviews {
/*if ([self.constraints count] > 0) {
if (!_didSetupConstraints) {
[NSLayoutConstraint deactivateConstraints:self.constraints];
[self autoSetDimension:ALDimensionHeight toSize:_subItemSize.height relation:NSLayoutRelationGreaterThanOrEqual];
[self autoSetDimension:ALDimensionWidth toSize:_subItemSize.width relation:NSLayoutRelationGreaterThanOrEqual];
}*/
if (_didSetupConstraints) {
[_subItemButton autoCenterInSuperview];
if (_type == TabBarSubItemsViewTypeCheckBox) {
[_subItemButton autoSetDimension:ALDimensionHeight toSize:_subItemSize.height];
[_subItemButton autoSetDimension:ALDimensionWidth toSize:_subItemSize.width];
}
if (_type == TabBarSubItemsViewTypeButton) {
[_subItemButton.layer setCornerRadius:_buttonCornerRadius];
}
_didSetupConstraints = YES;
}
}
- (void) itemSelected:(UIButton *) button {
[button setSelected:!button.isSelected];
if (button.isSelected) {
[_subItemButton.layer setBorderColor:[[@"ff4e50" colorFromHex] CGColor]];
}
else {
[_subItemButton.layer setBorderColor:[[@"999999" colorFromHex] CGColor]];
}
if (_delegate && [_delegate respondsToSelector:@selector(tabBarSubItem:didSelected:)]) {
[_delegate tabBarSubItem:self didSelected:button.isSelected];
}
}
- (void) setSelected:(BOOL) selected {
[_subItemButton setSelected:selected];
if (_subItemButton.isSelected) {
[_subItemButton.layer setBorderColor:[[@"ff4e50" colorFromHex] CGColor]];
}
else {
[_subItemButton.layer setBorderColor:[[@"999999" colorFromHex] CGColor]];
}
}
- (BOOL) isSelected {
return [_subItemButton isSelected];
}
@end
+32
View File
@@ -0,0 +1,32 @@
//
// AADatePicker.h
// CustomDatePicker
//
// Created by Amit Attias on 3/26/14.
// Copyright (c) 2014 I'm IT. All rights reserved.
//
#import <UIKit/UIKit.h>
@class AADatePicker;
@protocol AADatePickerDelegate <NSObject>
@optional
-(void)dateChanged:(AADatePicker*)datePicker;
@end
@interface AADatePicker : UIControl
@property (nonatomic, strong) id<AADatePickerDelegate> delegate;
@property (nonatomic, strong) NSDate *date;
@property (nonatomic) BOOL showOnlyValidDates;
@property (nonatomic) BOOL showsSelectionIndicator;
- (instancetype) initWithFrame:(CGRect)frame maxDate:(NSDate *)maxDate minDate:(NSDate *)minDate showValidDatesOnly:(BOOL)showValidDatesOnly;
- (void) resetPicker;
@end
+310
View File
@@ -0,0 +1,310 @@
//
// AADatePicker.m
// CustomDatePicker
//
// Created by Amit Attias on 3/26/14.
// Copyright (c) 2014 I'm IT. All rights reserved.
//
#import "AADatePicker.h"
#import <PureLayout/PureLayout.h>
#import "NSString+HexColor.h"
#import "NSDate+NSDate_Util.h"
@interface AADatePicker () <UIPickerViewDataSource, UIPickerViewDelegate>
{
NSInteger nDays;
}
@property (nonatomic, strong) UIPickerView *picker;
@property (nonatomic, strong) NSCalendar *calendar;
@property (nonatomic, strong) NSDate *minDate;
@property (nonatomic, strong) NSDate *maxDate;
@property (readonly, strong) NSDate *earliestPresentedDate;
@property (nonatomic) BOOL didSetupConstraints;
@end
@implementation AADatePicker
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (!self) {
return nil;
}
_minDate = [NSDate date];
[self commonInit];
return self;
}
- (id)initWithFrame:(CGRect)frame maxDate:(NSDate *)maxDate minDate:(NSDate *)minDate showValidDatesOnly:(BOOL)showValidDatesOnly
{
self = [super initWithFrame:frame];
if (!self) {
return nil;
}
assert((((minDate) && (maxDate)) && ([minDate compare:maxDate] != NSOrderedDescending)));
_minDate = minDate;
_maxDate = maxDate;
_showOnlyValidDates = showValidDatesOnly;
[self commonInit];
return self;
}
- (id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (!self) {
return nil;
}
[self commonInit];
return self;
}
- (void) layoutSubviews {
if (!_didSetupConstraints) {
[_picker autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
[_picker autoAlignAxisToSuperviewAxis:ALAxisVertical];
[_picker autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self];
[_picker autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self];
[_picker autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self];
[_picker autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self];
}
}
- (void) resetPicker {
[self showDateOnPicker:self.earliestPresentedDate];
}
-(NSDate *)earliestPresentedDate
{
return _showOnlyValidDates ? _minDate : [NSDate date];
}
- (void)commonInit {
[self setBackgroundColor:[UIColor clearColor]];
_showsSelectionIndicator = YES;
_calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
_picker = [[UIPickerView alloc] initWithFrame:self.bounds];
_picker.dataSource = self;
_picker.delegate = self;
[_picker setShowsSelectionIndicator:_showsSelectionIndicator];
[self initDate];
[self showDateOnPicker:_date];
[self addSubview:_picker];
}
- (void) setShowsSelectionIndicator:(BOOL)showsSelectionIndicator {
_showsSelectionIndicator = showsSelectionIndicator;
[_picker setShowsSelectionIndicator:_showsSelectionIndicator];
}
-(void)showDateOnPicker:(NSDate *)date
{
_date = date;
NSDateComponents *components = [_calendar
components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay
fromDate:self.earliestPresentedDate];
NSDate *fromDate = [_calendar dateFromComponents:components];
components = [_calendar components:(NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute)
fromDate:fromDate
toDate:date
options:0];
NSInteger hour = [components hour] + 24 * (INT16_MAX / 120);
NSInteger minute = [components minute] + 60 * (INT16_MAX / 120);
NSInteger day = [components day];
[_picker selectRow:day inComponent:0 animated:YES];
[_picker selectRow:hour inComponent:1 animated:YES];
[_picker selectRow:minute inComponent:2 animated:YES];
}
-(void)initDate
{
NSInteger startDayIndex = 0;
NSInteger startHourIndex = 0;
NSInteger startMinuteIndex = 0;
if ((_minDate) && (_maxDate) && _showOnlyValidDates) {
NSDateComponents *components = [_calendar components:NSCalendarUnitDay
fromDate:_minDate
toDate:_maxDate
options:0];
nDays = components.day + 1;
} else {
nDays = INT16_MAX;
}
NSDate *dateToPresent;
if ([_minDate compare:[NSDate date]] == NSOrderedDescending) {
dateToPresent = _minDate;
} else if ([_maxDate compare:[NSDate date]] == NSOrderedAscending) {
dateToPresent = _maxDate;
} else {
dateToPresent = [NSDate date];
}
NSDateComponents *todaysComponents = [_calendar components:NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute
fromDate:self.earliestPresentedDate
toDate:dateToPresent
options:0];
startDayIndex = todaysComponents.day;
startHourIndex = todaysComponents.hour;
startMinuteIndex = todaysComponents.minute;
_date = [NSDate dateWithTimeInterval:startDayIndex*24*60*60+startHourIndex*60*60+startMinuteIndex*60 sinceDate:self.earliestPresentedDate];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (component == 0)
{
return nDays;
}
else if (component == 1)
{
return INT16_MAX;
}
else
{
return INT16_MAX;
}
}
-(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
switch (component) {
case 0:
return 150;
break;
case 1:
return 50;
break;
case 2:
return 50;
break;
default:
return 0;
break;
}
}
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return 74;
}
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *lblDate = [[UILabel alloc] init];
[lblDate setBackgroundColor:[UIColor clearColor]];
switch (component) {
case 0:{
NSDate *aDate = [NSDate dateWithTimeInterval:row*24*60*60 sinceDate:self.earliestPresentedDate];
NSDateComponents *components = [_calendar components:(NSCalendarUnitEra|NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay) fromDate:[NSDate date]];
NSDate *today = [_calendar dateFromComponents:components];
components = [_calendar components:(NSCalendarUnitEra|NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay) fromDate:aDate];
NSDate *otherDate = [_calendar dateFromComponents:components];
if ([today isEqualToDate:otherDate]) {
[lblDate setText:NSLocalizedString(@"Today",@"")];
} else {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.locale = [NSLocale currentLocale];
formatter.dateFormat = @"MMM d";
[lblDate setText:[formatter stringFromDate:aDate]];
}
lblDate.textAlignment = NSTextAlignmentLeft;
break;
}
case 1:{
int max = (int)[_calendar maximumRangeOfUnit:NSCalendarUnitHour].length;
[lblDate setText:[NSString stringWithFormat:@"%02d",(row % max)]]; // 02d = pad with leading zeros to 2 digits
lblDate.textAlignment = NSTextAlignmentCenter;
break;
}
case 2:{
int max = (int)[_calendar maximumRangeOfUnit:NSCalendarUnitMinute].length;
[lblDate setText:[NSString stringWithFormat:@"%02d",(row % max)]];
lblDate.textAlignment = NSTextAlignmentLeft;
break;
}
default:
break;
}
NSDictionary *attributeDict = @{NSForegroundColorAttributeName : [@"ff4e50" colorFromHex],NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue" size:23]};
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:lblDate.text attributes:attributeDict];
lblDate.attributedText = attributedString;
return lblDate;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSInteger daysFromStart;
NSDate *chosenDate;
daysFromStart = [pickerView selectedRowInComponent:0];
chosenDate = [NSDate dateWithTimeInterval:daysFromStart*24*60*60 sinceDate:self.earliestPresentedDate];
NSInteger hour = [pickerView selectedRowInComponent:1];
NSInteger minute = [pickerView selectedRowInComponent:2];
// Build date out of the components we got
NSDateComponents *components = [_calendar components:(NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear) fromDate:chosenDate];
components.hour = hour % 24;
components.minute = minute % 60;
_date = [[_calendar dateFromComponents:components] toLocalTime];
if ([_date compare:_minDate] == NSOrderedAscending) {
[self showDateOnPicker:_minDate];
} else if ([_date compare:_maxDate] == NSOrderedDescending) {
[self showDateOnPicker:_maxDate];
}
if ((_delegate) && ([_delegate respondsToSelector:@selector(dateChanged:)])) {
[_delegate dateChanged:self];
}
}
@end
+120
View File
@@ -0,0 +1,120 @@
//
// NSDate+NSDate_Util.h
// Butlr
//
// Created by Giuseppe Nucifora on 11/02/14.
// Copyright (c) 2014 Meedori. All rights reserved.
//
#import <Foundation/Foundation.h>
#define kSunRiseMinutes 5*60
#define kSunSetMinutes 19*60
#define kMoonRiseMinutes 17*60
#define kMoonSetMinutes 7*60
static NSString *kNSDateHelperFormatFullDateWithTime = @"MMM d, yyyy h:mm a";
static NSString *kNSDateHelperFormatFullDate = @"MMM d, yyyy";
static NSString *kNSDateHelperFormatShortDateWithTime = @"MMM d h:mm a";
static NSString *kNSDateHelperFormatShortDate = @"MMM d";
static NSString *kNSDateHelperFormatWeekday = @"EEEE";
static NSString *kNSDateHelperFormatWeekdayWithTime = @"EEEE h:mm a";
static NSString *kNSDateHelperFormatTime = @"h:mm a";
static NSString *kNSDateHelperFormatTimeWithPrefix = @"'at' h:mm a";
static NSString *kNSDateHelperFormatSQLDate = @"yyyy-MM-dd";
static NSString *kNSDateHelperFormatSQLTime = @"HH:mm:ss";
static NSString *kNSDateHelperFormatSQLDateWithTime = @"yyyy-MM-dd HH:mm:ss";
static NSString *kNSDateHelperFormatSQLDate_shashSeparated = @"yyyy/MM/dd";
static NSString *kNSDateHelperFormatSQLDate_notSlashSeparated = @"yyyy-MM-dd";
static NSString *kNSDateHelperFormatSQLDateWithTime_shashSeparated = @"yyyy/MM/dd HH:mm:ss";
static NSString *kNSDateHelperFormatSQLDateIT = @"dd-MM-yyyy";
static NSString *kNSDateHelperFormatSQLDateEN = @"MM-dd-yyyy";
static NSString *kNSDateHelperFormatSQLDateIT_shashSeparated = @"dd/MM/yyyy";
static NSString *kNSDateHelperFormatSQLDateEN_shashSeparated = @"MM/dd/yyyy";
@interface NSDate (NSDate_Util)
- (NSDate *)dateToNearestMinutes:(NSInteger)minutes;
- (NSDate *) dateByAddingMinutes: (NSInteger) dMinutes;
- (NSDate *) dateByAddingHours:(NSInteger) hours;
- (NSDate*) dateByAddingDays:(NSInteger) days;
- (NSDate*) dateByAddingYears:(NSInteger) years;
- (NSDate *) dateBySubtractingMinutes: (NSInteger) dMinutes;
- (NSDate *) dateBySubtractingHours: (NSInteger) hours;
- (NSDate *) dateBySubtractingDays: (NSInteger) days;
- (NSDate *) dateBySubtractingYears: (NSInteger) years;
- (NSDate *) dateAtStartOfDay;
- (NSInteger) minutesAfterDate: (NSDate *) aDate;
- (CGFloat) distanceInWeeksToDate:(NSDate *)anotherDate;
- (CGFloat) distanceInDaysToDate:(NSDate *)anotherDate;
- (CGFloat) distanceInHoursToDate:(NSDate *)anotherDate;
- (CGFloat) distanceInMinutesToDate:(NSDate *)anotherDate;
- (CGFloat) distanceInSeconsToDate:(NSDate *)anotherDate;
-(NSDate *) toLocalTime;
-(NSDate *) toGlobalTime;
- (BOOL) isSameYearAsDate: (NSDate *) aDate;
- (BOOL) isEarlierThanDate: (NSDate *) aDate;
- (BOOL) isLaterThanDate: (NSDate *) aDate;
+ (void)initializeStatics;
+ (NSCalendar *)sharedCalendar;
+ (NSDateFormatter *)sharedDateFormatter;
- (NSUInteger)daysAgo;
- (NSUInteger)daysAgoAgainstMidnight;
- (NSString *)stringDaysAgo;
- (NSString *)stringDaysAgoAgainstMidnight:(BOOL)flag;
- (NSUInteger)monthDay;
- (NSUInteger)weekday;
- (NSUInteger)month;
- (NSUInteger)weekNumber;
- (NSUInteger)hour;
- (NSUInteger)minute;
- (NSUInteger)year;
- (long int)utcTimeStamp; //full seconds since
+ (NSDate *)dateFromString:(NSString *)string;
+ (NSDate *)dateFromString:(NSString *)string withFormat:(NSString *)format;
+ (NSDate *)dateFromString:(NSString *)string withFormat:(NSString *)format withTimeZone:(NSTimeZone*) timeZone;
+ (NSString *)stringFromDate:(NSDate *)date withFormat:(NSString *)string;
+ (NSString *)stringFromDate:(NSDate *)date;
+ (NSString *)stringForDisplayFromDate:(NSDate *)date;
+ (NSString *)stringForDisplayFromDate:(NSDate *)date prefixed:(BOOL)prefixed;
+ (NSString *)stringForDisplayFromDate:(NSDate *)date prefixed:(BOOL)prefixed alwaysDisplayTime:(BOOL)displayTime;
- (NSString *)string;
- (NSString *)stringWithFormat:(NSString *)format;
- (NSString *)stringWithFormat:(NSString *)format timeZone:(NSTimeZone*) timezone;
- (NSString *)stringWithDateStyle:(NSDateFormatterStyle)dateStyle timeStyle:(NSDateFormatterStyle)timeStyle;
- (NSDate *)beginningOfWeek;
- (NSDate *)beginningOfDay;
- (NSDate *)endOfWeek;
+ (NSString *)dateFormatString;
+ (NSString *)timeFormatString;
+ (NSString *)timestampFormatString;
+ (NSString *)dbFormatString;
+ (NSString *) parseDateFormatFromString:(NSString *)dateString;
+ (NSString *) WCFStringFromDate:(NSDate*) date;
+ (NSArray*) getSlotTimesFromDate:(NSDate*) date distanceMinutes:(NSInteger) minutes;
- (BOOL)isSameDayAsDate:(NSDate*)otherDate;
+ (NSString *) getUniversalHourFromDateString:(NSString *)string formatterString:(NSString*) formatterString andUppercaseString:(BOOL)uppercaseString;
- (NSString *) getUniversalHourUppercaseString:(BOOL)uppercaseString;
- (NSString *)getNotificationUniversalHourUppercaseString:(BOOL)uppercaseString;
@end
File diff suppressed because it is too large. Load diff
+13
View File
@@ -0,0 +1,13 @@
//
// ToucheableScrollView.m
// cinecitta
//
// Created by Mario Nolassi on 11/16/11.
// Copyright (c) 2011 meedori. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ToucheableScrollView : UIScrollView
@end
+32
View File
@@ -0,0 +1,32 @@
//
// ToucheableScrollView.m
// cinecitta
//
// Created by Mario Nolassi on 11/16/11.
// Copyright (c) 2011 meedori. All rights reserved.
//
#import "ToucheableScrollView.h"
@implementation ToucheableScrollView
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
{
// If not dragging, send event to next responder
if (!self.dragging) {
if ([self.nextResponder respondsToSelector:@selector(touchesEnded:withEvent:)]) {
[self.nextResponder touchesEnded: touches withEvent:event];
}
if ([self.nextResponder.nextResponder respondsToSelector:@selector(touchesEnded:withEvent:)]) {
[self.nextResponder.nextResponder touchesEnded: touches withEvent:event];
}
}
else {
[super touchesEnded: touches withEvent: event];
}
}
@end