diff --git a/Pod/Classes/TabBarItem.m b/Pod/Classes/TabBarItem.m index 5f77948..394bae1 100644 --- a/Pod/Classes/TabBarItem.m +++ b/Pod/Classes/TabBarItem.m @@ -45,7 +45,7 @@ [_itemButton setBackgroundColor:[@"ff4e50" colorFromHex] forState:UIControlStateHighlighted]; [self addSubview:_itemButton]; - + } return self; } @@ -94,6 +94,10 @@ [_itemButton setHighlighted:highlighted]; } +- (void) setItemName:(NSString *)itemName { + [_itemSubView setItemName:itemName]; +} + - (void) itemButtonTapped { if (_delegate && [_delegate respondsToSelector:@selector(tabBarItemSelected:)]) { [_delegate tabBarItemSelected:self]; diff --git a/Pod/Classes/TabBarPicker.m b/Pod/Classes/TabBarPicker.m index 1ffc444..546b62b 100644 --- a/Pod/Classes/TabBarPicker.m +++ b/Pod/Classes/TabBarPicker.m @@ -12,6 +12,7 @@ #import "MMCPSScrollView.h" #import #import "NSString+HexColor.h" +#import @interface TabBarPicker() @@ -25,6 +26,7 @@ @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; @@ -72,7 +74,11 @@ _tabBarView = [[UIView alloc] initForAutoLayout]; - [self addSubview:_tabBarView]; + _separator = [[UIView alloc] initForAutoLayout]; + [_separator.layer setMasksToBounds:NO]; + [_separator setBackgroundColor:[[UIColor lightGrayColor] colorWithAlphaComponent:0.3]]; + + for (NSObject *item in items) { if (item && [item isKindOfClass:[TabBarItem class]]) { @@ -93,6 +99,10 @@ [_subItemScrollView setPageSize:1]; [self addSubview:_subItemScrollView]; + + [self addSubview:_tabBarView]; + + [self addSubview:_separator]; } [self updateConstraintsIfNeeded]; @@ -160,6 +170,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]; @@ -394,11 +408,32 @@ #pragma mark MMCPSScrollViewDelegate - (void)scrollView:(MMCPSScrollView *)scrollView didScrollToPage:(NSUInteger)pageIndex { - NSLog(@"The MMCPSScrollView is now on page %i.", pageIndex); + if ([scrollView currentPage] > 0 && [scrollView currentPage] <= [_tabBarItems count]) { + 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 - diff --git a/Pod/Classes/TabBarPickerSubItemsView.h b/Pod/Classes/TabBarPickerSubItemsView.h index 6061c75..08aa294 100644 --- a/Pod/Classes/TabBarPickerSubItemsView.h +++ b/Pod/Classes/TabBarPickerSubItemsView.h @@ -51,4 +51,5 @@ typedef NS_ENUM(NSInteger, TabBarPickerSubItemsViewType) { - (instancetype) initWithType:(TabBarPickerSubItemsViewType) type subItems:(NSArray*) subItems needsLocalization:(BOOL) needsLocalization; +- (void) setItemName:(NSString *) itemName; @end diff --git a/Pod/Classes/TabBarPickerSubItemsView.m b/Pod/Classes/TabBarPickerSubItemsView.m index 0af7d87..da39337 100644 --- a/Pod/Classes/TabBarPickerSubItemsView.m +++ b/Pod/Classes/TabBarPickerSubItemsView.m @@ -23,6 +23,7 @@ @property (nonatomic, strong) UILabel *switchBarLabel; @property (nonatomic, strong) UIButton *localizationButton; @property (nonatomic, strong) UIView *contentView; +@property (nonatomic, strong) NSString *name; @end @@ -45,7 +46,6 @@ _switchBarLabel = [[UILabel alloc] initForAutoLayout]; [_switchBarLabel setTextColor:[@"999999" colorFromHex]]; - [_switchBarLabel setText:NSLocalizedString(@"Distance", @"")]; [_switchBarView addSubview:_switchBarLabel]; _itemSwich = [[UISwitch alloc] initForAutoLayout]; @@ -65,7 +65,7 @@ if (_needsLocalization) { _localizationView = [[UIView alloc] initForAutoLayout]; - [_localizationView setBackgroundColor:[UIColor purpleColor]]; + [_localizationView setBackgroundColor:[UIColor whiteColor]]; [_localizationView setAlpha:0]; _localizationButton = [[UIButton alloc] initForAutoLayout]; @@ -98,6 +98,8 @@ [UIView animateWithDuration:0.5 animations:^{ [_localizationView setAlpha:[[NSNumber numberWithBool:[[SharedLocationManager sharedManager] localizationIsAuthorized]] floatValue]]; + [_itemSwich setUserInteractionEnabled:NO]; + [_itemSwich setOn:NO]; }]; if (!_didSetupConstraints) { @@ -188,4 +190,8 @@ [super touchesBegan: touches withEvent:event]; } +- (void) setItemName:(NSString *) itemName { + [_switchBarLabel setText:itemName]; +} + @end diff --git a/Pod/Classes/Vendor/MMCPSScrollView/MMCPSScrollView.h b/Pod/Classes/Vendor/MMCPSScrollView/MMCPSScrollView.h index 6161502..d658b90 100755 --- a/Pod/Classes/Vendor/MMCPSScrollView/MMCPSScrollView.h +++ b/Pod/Classes/Vendor/MMCPSScrollView/MMCPSScrollView.h @@ -45,7 +45,7 @@ typedef enum { // Time it takes to scroll to next page @property (nonatomic) CGFloat scrollingTime; -@property (nonatomic) NSUInteger currentPage; +@property (nonatomic) NSInteger currentPage; @property (nonatomic, assign) id MMCPSDelegate;