This commit is contained in:
Giuseppe Nucifora 2015-07-21 09:21:33 +02:00
parent c2be9705ac
commit 603962375e
18 changed files with 1659 additions and 1424 deletions

View File

@ -0,0 +1 @@
../../../../../Pod/Classes/TabBarPickerSubItemsView.h

View File

@ -0,0 +1 @@
../../../../../Pod/Classes/TabBarPickerSubItemsView.h

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "66A365F03E2E5FD04D4DAC69"
BlueprintIdentifier = "F1DAA46C7CBB0FB9B92A7891"
BuildableName = "TabBarPicker.bundle"
BlueprintName = "Pods-TabBarPicker_Example-TabBarPicker-TabBarPicker"
ReferencedContainer = "container:Pods.xcodeproj">

View File

@ -14,7 +14,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "4F73FDE94825965417E35D5A"
BlueprintIdentifier = "FD042F8BAEE7119C1EA51707"
BuildableName = "TabBarPicker.framework"
BlueprintName = "Pods-TabBarPicker_Example-TabBarPicker"
ReferencedContainer = "container:Pods.xcodeproj">

View File

@ -14,7 +14,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "7C0EACB3AF64706AA504E8BE"
BlueprintIdentifier = "AFD4CD498974811C4E61A02F"
BuildableName = "TabBarPicker.bundle"
BlueprintName = "Pods-TabBarPicker_Tests-TabBarPicker-TabBarPicker"
ReferencedContainer = "container:Pods.xcodeproj">

View File

@ -14,7 +14,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "113B2CE1962FE34F95B1D5AD"
BlueprintIdentifier = "B372419045A1236C95998EEE"
BuildableName = "TabBarPicker.framework"
BlueprintName = "Pods-TabBarPicker_Tests-TabBarPicker"
ReferencedContainer = "container:Pods.xcodeproj">

View File

@ -2,6 +2,7 @@
#import "TabBarItem.h"
#import "TabBarPicker.h"
#import "TabBarPickerSubItemsView.h"
#import "TabBarSubItem.h"
FOUNDATION_EXPORT double TabBarPickerVersionNumber;

View File

@ -2,6 +2,7 @@
#import "TabBarItem.h"
#import "TabBarPicker.h"
#import "TabBarPickerSubItemsView.h"
#import "TabBarSubItem.h"
FOUNDATION_EXPORT double TabBarPickerVersionNumber;

View File

@ -59,7 +59,10 @@
[allergen setSelectedImage:[UIImage imageNamed:@"allergen_on"]];
tabbar = [[TabBarPicker alloc] initWithTabBarItems:@[location,calendar,type,price,allergen] forPosition:TabBarPickerPositionBottom];
[tabbar setBackgroundColor:[UIColor whiteColor]];
[tabbar addItem:allergen];
}
return self;
}
@ -70,17 +73,7 @@
[contentView addSubview:tabbar];
/*[tabbar autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeTop];
tabbar ali
[tabbar autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:50 relation:NSLayoutRelationGreaterThanOrEqual];
[tabbar autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:50 relation:NSLayoutRelationGreaterThanOrEqual];
*/
NSLog(@"%f %f",tabbar.frame.size.width,tabbar.frame.size.height);
self.view = contentView;
[self.view setNeedsUpdateConstraints];
}
- (void)viewDidLoad
@ -89,7 +82,25 @@
//[self.view setBackgroundColor:[UIColor lightGrayColor]];
// Do any additional setup after loading the view, typically from a nib.
[super updateViewConstraints];
}
- (void) viewDidAppear:(BOOL)animated {
TabBarSubItem *subItem1 = [TabBarSubItem tabBarSubItemWithName:@"Peppe"];
TabBarSubItem *subItem2 = [TabBarSubItem tabBarSubItemWithName:@"Peppe1"];
TabBarSubItem *subItem3 = [TabBarSubItem tabBarSubItemWithName:@"Peppe2"];
TabBarSubItem *subItem4 = [TabBarSubItem tabBarSubItemWithName:@"Peppe3"];
TabBarSubItem *subItem5 = [TabBarSubItem tabBarSubItemWithName:@"Peppe4"];
TabBarSubItem *subItem6 = [TabBarSubItem tabBarSubItemWithName:@"Peppe5"];
TabBarSubItem *subItem7 = [TabBarSubItem tabBarSubItemWithName:@"Peppe6"];
TabBarItem *allergen = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
[allergen setItemName:@"Allergen"];
[allergen setImage:[UIImage imageNamed:@"allergen_off"]];
[allergen setSelectedImage:[UIImage imageNamed:@"allergen_on"]];
[tabbar addItem:allergen];
}
- (void)didReceiveMemoryWarning

View File

@ -9,6 +9,16 @@
#import <Foundation/Foundation.h>
#import "TabBarSubItem.h"
@class TabBarItem;
@protocol TabBarItemDelegate <NSObject>
@required
- (void) tabBarItemSelected:(TabBarItem*) selectedItem;
@end
@interface TabBarItem : UIView
/**
@ -27,6 +37,10 @@
* Represents the sub items that appeare when you select the item in picker.
*/
@property (nonatomic, strong) NSMutableArray *subItems;
/**
* <#Description#>
*/
@property (nonatomic, assign) id<TabBarItemDelegate> delegate;
/**
* <#Description#>

View File

@ -11,6 +11,8 @@
@interface TabBarItem()
@property (nonatomic, strong) UIButton *itemButton;
@property (nonatomic) UIDeviceOrientation orientation;
@end
@ -21,9 +23,13 @@
self = [self initForAutoLayout];
if (self) {
NSAssert(array, @"SubItemsArray cannot be nil");
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
_orientation = [[UIDevice currentDevice] orientation];
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
_itemButton = [[UIButton alloc] initForAutoLayout];
[self addSubview:_itemButton];
_subItems = [[NSMutableArray alloc] init];
@ -36,11 +42,26 @@
return self;
}
- (void) layoutSubviews {
[_itemButton autoPinEdgesToSuperviewMargins];
}
- (void)deviceOrientationDidChange:(NSNotification *)notification {
//Obtain current device orientation
_orientation = [[UIDevice currentDevice] orientation];
[self layoutSubviews];
}
- (void) setImage:(UIImage *)image {
[_itemButton setImage:image forState:UIControlStateNormal];
}
- (void) setSelectedImage:(UIImage *)selectedImage {
[_itemButton setImage:selectedImage forState:UIControlStateSelected];
}
@end

View File

@ -10,26 +10,33 @@
#import "TabbarItem.h"
#import "TabBarSubItem.h"
typedef enum
{
typedef NS_ENUM(NSInteger, TabBarPickerPosition) {
// Informational
TabBarPickerPositionLeft,
TabBarPickerPositionRight,
TabBarPickerPositionBottom
TabBarPickerPositionBottom,
TabBarPickerPositionTop
} TabBarPickerPosition;
};
@interface TabBarPicker : UIView
@property (nonatomic, strong) NSMutableArray *tabBarItems;
@property (nonatomic, strong, readonly) NSMutableArray *tabBarItems;
@property (nonatomic, readonly) CGSize tabBarSize;
@property (nonatomic) TabBarPickerPosition position;
@property (nonatomic, readonly) TabBarPickerPosition position;
@property (nonatomic, readonly) NSLayoutRelation layoutRelation;
@property (nonatomic) CGFloat paddingLeft;
@property (nonatomic) CGFloat paddingRight;
@property (nonatomic) CGFloat paddingTop;
@property (nonatomic) CGFloat paddingBottom;
@property (nonatomic) CGFloat itemSpacing;
/**
* Init TabBarPicker with items. When is selected an item the picher show down subitems.
* By default when one of more subItems are selected the selected item become selected.
* By default the tabBar size is max screen width and 100px height
* The picker size is dinamically based the max subitems of items.
* For this method is used NSLayoutRelationEqual as NSLayoutRelation configuration.
*
* @param items Represents tab bar items. That array cannot be nil.
*
@ -43,6 +50,26 @@ typedef enum
*/
- (instancetype) initWithTabBarItems:(NSArray *)items forPosition:(TabBarPickerPosition)position;
/**
* Init TabBarPicker with items. When is selected an item the picher show down subitems.
* By default when one of more subItems are selected the selected item become selected.
* By default the tabBar size is max screen width and 100px height
* The picker size is dinamically based the max subitems of items.
*
* @param items Represents tab bar items. That array cannot be nil.
*
* @param position Represents the posizion in the Screen:
* - TabBarPickerPositionLeft : Is positioned in vertical on left of the screen and shows the picker at its right
* - TabBarPickerPositionRight : Is positioned in vertical on right of the screen and shows the picker at its left
* - TabBarPickerPositionBottom : Is positioned in horizontal on bottom of the screen and shows the picker at its top
* - TabBarPickerPositionTop : Is positioned in horizontal on top of the screen and shows the picker at its bottom
*
* @param relation Represents NSLayoutRelation for TabBar layout.
*
* @return raturn instance of TabBarPicker object.
*/
- (instancetype) initWithTabBarItems:(NSArray *)items forPosition:(TabBarPickerPosition)position andNSLayoutRelation:(NSLayoutRelation) relation;
/**
* Init TabBarPicker with items. When is selected an item the picher show down subitems.
* By default when one of more subItems are selected the selected item become selected.
@ -58,8 +85,17 @@ typedef enum
* - TabBarPickerPositionBottom : Is positioned in horizontal on bottom of the screen and shows the picker at its top
* - TabBarPickerPositionTop : Is positioned in horizontal on top of the screen and shows the picker at its bottom
*
* @param relation Represents NSLayoutRelation for TabBar layout.
*
* @return raturn instance of TabBarPicker object.
*/
- (instancetype) initWithTabBarItems:(NSArray*) items withTabBarSize:(CGSize) size forPosition:(TabBarPickerPosition) position;
- (instancetype) initWithTabBarItems:(NSArray*) items withTabBarSize:(CGSize) size forPosition:(TabBarPickerPosition) position andNSLayoutRelation:(NSLayoutRelation) relation;
/**
* <#Description#>
*
* @param item <#item description#>
*/
- (void) addItem:(TabBarItem*) item;
@end

View File

@ -8,11 +8,9 @@
#import "TabBarPicker.h"
#import <PureLayout/PureLayout.h>
#import "TabBarPickerSubItemsView.h"
#define tabBarSizeVertical CGSizeMake()
@interface TabBarPicker()
@interface TabBarPicker() <TabBarItemDelegate>
@property (nonatomic) UIDeviceOrientation orientation;
@ -22,19 +20,33 @@
- (instancetype) initWithTabBarItems:(NSArray *)items forPosition:(TabBarPickerPosition)position {
return [self initWithTabBarItems:items withTabBarSize:CGSizeZero forPosition:position];
return [self initWithTabBarItems:items withTabBarSize:CGSizeZero forPosition:position andNSLayoutRelation:NSLayoutRelationEqual];
}
- (instancetype) initWithTabBarItems:(NSArray*) items withTabBarSize:(CGSize) size forPosition:(TabBarPickerPosition) position {
- (instancetype) initWithTabBarItems:(NSArray *)items forPosition:(TabBarPickerPosition)position andNSLayoutRelation:(NSLayoutRelation)relation {
return [self initWithTabBarItems:items withTabBarSize:CGSizeZero forPosition:position andNSLayoutRelation:relation];
}
- (instancetype) initWithTabBarItems:(NSArray*) items withTabBarSize:(CGSize) size forPosition:(TabBarPickerPosition) position andNSLayoutRelation:(NSLayoutRelation)relation {
self = [self initForAutoLayout];
if (self) {
_itemSpacing = 10;
_paddingLeft = 0;
_paddingRight = 0;
_paddingTop = 0;
_paddingBottom = 0;
_layoutRelation = relation;
_position = position;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
NSAssert(items, @"TabBar Items array cannot be nil!");
if (CGSizeEqualToSize(size, CGSizeZero)) {
@ -42,26 +54,91 @@
}
_tabBarItems = [[NSMutableArray alloc] init];
for (NSObject *item in items) {
if ([item isKindOfClass:[TabBarItem class]]) {
[_tabBarItems addObject:item];
}
[self addItem:item];
}
}
[self setNeedsUpdateConstraints];
return self;
}
- (void) layoutSubviews {
[self autoSetDimension:ALDimensionHeight toSize:44];
[self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview];
[self autoPinEdgeToSuperviewMargin:ALEdgeBottom];
switch (_position) {
case TabBarPickerPositionLeft:{
[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:20];
[self autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
[self autoSetDimension:ALDimensionWidth toSize:44];
[self autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self.superview withOffset:0 relation:_layoutRelation];
[self autoAlignAxisToSuperviewMarginAxis:ALAxisHorizontal];
[_tabBarItems autoSetViewsDimension:ALDimensionWidth toSize:44.0];
[_tabBarItems autoDistributeViewsAlongAxis:ALAxisVertical alignedTo:ALAttributeVertical withFixedSpacing:_itemSpacing insetSpacing:YES matchedSizes:YES];
[[_tabBarItems firstObject] autoAlignAxisToSuperviewAxis:ALAxisVertical];
}
break;
case TabBarPickerPositionRight:{
[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:20];
[self autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:0];
[self autoSetDimension:ALDimensionWidth toSize:44];
[self autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self.superview withOffset:0 relation:_layoutRelation];
[self autoAlignAxisToSuperviewMarginAxis:ALAxisHorizontal];
[_tabBarItems autoSetViewsDimension:ALDimensionWidth toSize:44.0];
[_tabBarItems autoDistributeViewsAlongAxis:ALAxisVertical alignedTo:ALAttributeVertical withFixedSpacing:_itemSpacing insetSpacing:YES matchedSizes:YES];
[[_tabBarItems firstObject] autoAlignAxisToSuperviewAxis:ALAxisVertical];
}
break;
case TabBarPickerPositionTop:{
[self autoPinEdgeToSuperviewMargin:ALEdgeTop];
[self autoSetDimension:ALDimensionHeight toSize:44];
[self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:_layoutRelation];
[self autoAlignAxisToSuperviewMarginAxis:ALAxisVertical];
[_tabBarItems autoSetViewsDimension:ALDimensionHeight toSize:44.0];
[_tabBarItems autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:_itemSpacing insetSpacing:YES matchedSizes:YES];
[[_tabBarItems firstObject] autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
}
break;
case TabBarPickerPositionBottom:
default:{
[self autoPinEdgeToSuperviewMargin:ALEdgeBottom];
[self autoSetDimension:ALDimensionHeight toSize:44];
[self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:_layoutRelation];
[self autoAlignAxisToSuperviewMarginAxis:ALAxisVertical];
[_tabBarItems autoSetViewsDimension:ALDimensionHeight toSize:44.0];
[_tabBarItems autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:0 insetSpacing:YES matchedSizes:YES];
[[_tabBarItems firstObject] autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
}
break;
}
[self updateConstraints];
}
- (void) setPosition:(TabBarPickerPosition)position {
_position = position;
for (TabBarItem *item in _tabBarItems) {
if (self.superview) {
[self removeConstraints:self.constraints];
for (TabBarItem *item in _tabBarItems) {
[item removeConstraints:item.constraints];
}
[self layoutSubviews];
}
}
@ -72,6 +149,29 @@
[self layoutSubviews];
}
- (void) addItem:(TabBarItem*) item {
if (item && [item isKindOfClass:[TabBarItem class]]) {
NSLog(@"%@",self.constraints);
[_tabBarItems addObject:item];
[item setBackgroundColor:[UIColor lightGrayColor]];
[item setDelegate:self];
[self addSubview:item];
if (self.superview) {
[self removeConstraints:self.constraints];
for (TabBarItem *item in _tabBarItems) {
[item removeConstraints:item.constraints];
}
[self layoutSubviews];
}
}
}
- (void) layoutSubviewsPortrait {
}

View File

@ -0,0 +1,14 @@
//
// TabBarPickerSubItemsView.h
// Pods
//
// Created by Giuseppe Nucifora on 17/07/15.
//
//
#import <UIKit/UIKit.h>
@interface TabBarPickerSubItemsView : UIView
@end

View File

@ -0,0 +1,23 @@
//
// TabBarPickerSubItemsView.m
// Pods
//
// Created by Giuseppe Nucifora on 17/07/15.
//
//
#import "TabBarPickerSubItemsView.h"
#import <PureLayout/PureLayout.h>
@implementation TabBarPickerSubItemsView
- (instancetype) init {
self = [self initForAutoLayout];
if (self) {
}
return self;
}
@end

View File

@ -7,7 +7,6 @@
//
#import <Foundation/Foundation.h>
//#import "PureLayout.h"
@interface TabBarSubItem : UIView

View File

@ -39,6 +39,7 @@
//Obtain current device orientation
_orientation = [[UIDevice currentDevice] orientation];
[self layoutSubviews];
}