- Fix object

This commit is contained in:
Giuseppe Nucifora 2015-08-07 18:29:24 +02:00
parent d4dbaff0e7
commit 091bb39d54
7 changed files with 86 additions and 135 deletions

View File

@ -35,33 +35,38 @@
TabBarItem *location = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]]; TabBarItem *location = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
[location setItemName:@"Location"]; [location setItemName:@"Location"];
[location setImage:[UIImage imageNamed:@"location_off"]]; [location setImage:[UIImage imageNamed:@"location"]];
[location setSelectedImage:[UIImage imageNamed:@"location_on"]]; [location setSelectedImage:[UIImage imageNamed:@"location_selected"]];
[location setHighlightedImage:[UIImage imageNamed:@"location_highlighted"]];
TabBarItem *calendar = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]]; TabBarItem *calendar = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
[calendar setItemName:@"Calendar"]; [calendar setItemName:@"Calendar"];
[calendar setImage:[UIImage imageNamed:@"calendar_off"]]; [calendar setImage:[UIImage imageNamed:@"calendar"]];
[calendar setSelectedImage:[UIImage imageNamed:@"calendar_on"]]; [calendar setSelectedImage:[UIImage imageNamed:@"calendar_selected"]];
[calendar setHighlightedImage:[UIImage imageNamed:@"calendar_highlighted"]];
TabBarItem *type = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]]; TabBarItem *type = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
[type setItemName:@"Type"]; [type setItemName:@"Type"];
[type setImage:[UIImage imageNamed:@"type_off"]]; [type setImage:[UIImage imageNamed:@"type"]];
[type setSelectedImage:[UIImage imageNamed:@"type_on"]]; [type setSelectedImage:[UIImage imageNamed:@"type_selected"]];
[type setHighlightedImage:[UIImage imageNamed:@"type_highlighted"]];
TabBarItem *price = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]]; TabBarItem *price = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
[price setItemName:@"Price"]; [price setItemName:@"Price"];
[price setImage:[UIImage imageNamed:@"price_off"]]; [price setImage:[UIImage imageNamed:@"price"]];
[price setSelectedImage:[UIImage imageNamed:@"price_on"]]; [price setSelectedImage:[UIImage imageNamed:@"price_selected"]];
[price setHighlightedImage:[UIImage imageNamed:@"price_highlighted"]];
TabBarItem *allergen = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]]; TabBarItem *allergen = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
[allergen setItemName:@"Allergen"]; [allergen setItemName:@"Allergen"];
[allergen setImage:[UIImage imageNamed:@"allergen_off"]]; [allergen setImage:[UIImage imageNamed:@"allergen"]];
[allergen setSelectedImage:[UIImage imageNamed:@"allergen_on"]]; [allergen setSelectedImage:[UIImage imageNamed:@"allergen_selected"]];
[allergen setHighlightedImage:[UIImage imageNamed:@"allergen_highlighted"]];
/*TabBarItem *allergen2 = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]]; /*TabBarItem *allergen2 = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
[allergen2 setItemName:@"Allergen"]; [allergen2 setItemName:@"Allergen"];
[allergen2 setImage:[UIImage imageNamed:@"allergen_off"]]; [allergen2 setImage:[UIImage imageNamed:@"allergen"]];
[allergen2 setSelectedImage:[UIImage imageNamed:@"allergen_on"]]; [allergen2 setSelectedImage:[UIImage imageNamed:@"allergen_selected"]];
*/ */
tabbar = [[TabBarPicker alloc] initWithTabBarItems:@[location,calendar,type,price,allergen] forPosition:TabBarPickerPositionBottom]; tabbar = [[TabBarPicker alloc] initWithTabBarItems:@[location,calendar,type,price,allergen] forPosition:TabBarPickerPositionBottom];
[tabbar setItemSpacing:0]; [tabbar setItemSpacing:0];
@ -95,9 +100,7 @@
- (void) viewDidAppear:(BOOL)animated { - (void) viewDidAppear:(BOOL)animated {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [tabbar selectItem:0];
[tabbar show];
});
/*TabBarSubItem *subItem1 = [TabBarSubItem tabBarSubItemWithName:@"Peppe"]; /*TabBarSubItem *subItem1 = [TabBarSubItem tabBarSubItemWithName:@"Peppe"];
TabBarSubItem *subItem2 = [TabBarSubItem tabBarSubItemWithName:@"Peppe1"]; TabBarSubItem *subItem2 = [TabBarSubItem tabBarSubItemWithName:@"Peppe1"];
@ -109,8 +112,8 @@
TabBarItem *allergen = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]]; TabBarItem *allergen = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
[allergen setItemName:@"Allergen"]; [allergen setItemName:@"Allergen"];
[allergen setImage:[UIImage imageNamed:@"allergen_off"]]; [allergen setImage:[UIImage imageNamed:@"allergen"]];
[allergen setSelectedImage:[UIImage imageNamed:@"allergen_on"]]; [allergen setSelectedImage:[UIImage imageNamed:@"allergen_selected"]];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[tabbar addItem:allergen]; [tabbar addItem:allergen];

View File

@ -30,9 +30,13 @@
*/ */
@property (nonatomic, strong) UIImage *selectedImage; @property (nonatomic, strong) UIImage *selectedImage;
/** /**
* <#Description#> * Represents the image visible in picker when item is highlited.
*/ */
@property (nonatomic, strong) UIColor *highlightColor; @property (nonatomic, strong) UIImage *highlightedImage;
/**
* Represents the color of picker item when is highlited.
*/
@property (nonatomic, strong) UIColor *highlightedColor;
/** /**
* Represents the name of the item that can be shown in picker. * Represents the name of the item that can be shown in picker.

View File

@ -9,6 +9,7 @@
#import "TabBarItem.h" #import "TabBarItem.h"
#import <PureLayout/PureLayout.h> #import <PureLayout/PureLayout.h>
#import "NSString+HexColor.h" #import "NSString+HexColor.h"
#import <UIButton+BackgroundColor/UIButton+BackgroundColor.h>
@interface TabBarItem() @interface TabBarItem()
@ -31,7 +32,7 @@
_itemButton = [[UIButton alloc] initForAutoLayout]; _itemButton = [[UIButton alloc] initForAutoLayout];
[_itemButton addTarget:self action:@selector(itemButtonTapped) forControlEvents:UIControlEventTouchUpInside]; [_itemButton addTarget:self action:@selector(itemButtonTapped) forControlEvents:UIControlEventTouchUpInside];
_highlightColor = [@"ff4e50" colorFromHex]; [_itemButton setBackgroundColor:[@"ff4e50" colorFromHex] forState:UIControlStateHighlighted];
[self addSubview:_itemButton]; [self addSubview:_itemButton];
@ -71,29 +72,40 @@
- (void) setSelectedImage:(UIImage *)selectedImage { - (void) setSelectedImage:(UIImage *)selectedImage {
[_itemButton setImage:selectedImage forState:UIControlStateSelected]; [_itemButton setImage:selectedImage forState:UIControlStateSelected];
[_itemButton setImage:selectedImage forState:UIControlStateSelected|UIControlStateHighlighted];
} }
- (void) setHighlightColor:(UIColor *)highlightColor { - (void) setHighlightedImage:(UIImage *)highlightedImage {
[_itemButton setImage:highlightedImage forState:UIControlStateHighlighted];
[_itemButton setImage:highlightedImage forState:UIControlStateHighlighted|UIControlStateNormal];
}
- (void) setHighlightedColor:(UIColor *)highlightedColor {
_highlightedColor = highlightedColor;
_highlightColor = highlightColor;
} }
- (void) setHighlighted:(BOOL) highlighted { - (void) setHighlighted:(BOOL) highlighted {
[_itemButton setHighlighted:highlighted]; [_itemButton setHighlighted:highlighted];
if ([_itemButton isHighlighted]) { if ([_itemButton isHighlighted]) {
[_itemButton setBackgroundColor:_highlightColor];
[_itemButton setBackgroundColor:_highlightedColor];
} }
else { else {
[_itemButton setBackgroundColor:[UIColor clearColor]]; [_itemButton setBackgroundColor:[UIColor clearColor]];
} }
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isSelected]]);
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isHighlighted]]);
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isEnabled]]);
NSLog(@"%ld",_itemButton.state);
} }
- (void) itemButtonTapped { - (void) itemButtonTapped {
if ([_itemButton isHighlighted]) { if ([_itemButton isHighlighted]) {
[_itemButton setBackgroundColor:_highlightColor];
[_itemButton setBackgroundColor:_highlightedColor];
} }
else { else {
[_itemButton setBackgroundColor:[UIColor clearColor]]; [_itemButton setBackgroundColor:[UIColor clearColor]];
@ -102,6 +114,13 @@
if (_delegate && [_delegate respondsToSelector:@selector(tabBarItemSelected:)]) { if (_delegate && [_delegate respondsToSelector:@selector(tabBarItemSelected:)]) {
[_delegate tabBarItemSelected:self]; [_delegate tabBarItemSelected:self];
} }
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isSelected]]);
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isHighlighted]]);
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isEnabled]]);
NSLog(@"%ld",_itemButton.state);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[_itemButton setHighlighted:YES];
});
} }
@end @end

View File

@ -9,6 +9,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "TabbarItem.h" #import "TabbarItem.h"
#import "TabBarSubItem.h" #import "TabBarSubItem.h"
#import "TabBarPickerSubItemsView.h"
typedef NS_ENUM(NSInteger, TabBarPickerPosition) { typedef NS_ENUM(NSInteger, TabBarPickerPosition) {
// Informational // Informational
@ -91,54 +92,6 @@ typedef NS_ENUM(NSInteger, TabBarPickerPosition) {
*/ */
- (instancetype) initWithTabBarItems:(NSArray*) items withTabBarSize:(CGSize) size forPosition:(TabBarPickerPosition) position andNSLayoutRelation:(NSLayoutRelation) relation; - (instancetype) initWithTabBarItems:(NSArray*) items withTabBarSize:(CGSize) size 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.
* The picker size is dinamically based the max subitems of items
*
* @param items Represents tab bar items. That array cannot be nil.
*
* @param size Represents the tabbar size
*
* @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.
*
* @param subItemsPerRow Represents the number of subItems per single row of subitem picker
*
* @return <#return value description#>
*/
- (instancetype) initWithTabBarItems:(NSArray*) items withTabBarSize:(CGSize) size forPosition:(TabBarPickerPosition) position andNSLayoutRelation:(NSLayoutRelation) relation subItemsPerRow:(NSUInteger) subItemsPerRow;
/**
* 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.
* The picker size is dinamically based the max subitems of items
*
* @param items Represents tab bar items. That array cannot be nil.
*
* @param size Represents the tabbar size
*
* @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.
*
* @param subItemsPerRow Represents the number of subItems per single row of subitem picker
*
* @param subItemHeight Represents the height of single subItem.
*
* @return <#return value description#>
*/
- (instancetype) initWithTabBarItems:(NSArray*) items withTabBarSize:(CGSize) size forPosition:(TabBarPickerPosition) position andNSLayoutRelation:(NSLayoutRelation) relation subItemsPerRow:(NSUInteger) subItemsPerRow subItemHeight:(CGFloat) subItemHeight;
/** /**
* <#Description#> * <#Description#>
* *
@ -146,6 +99,8 @@ typedef NS_ENUM(NSInteger, TabBarPickerPosition) {
*/ */
- (void) addItem:(TabBarItem*) item; - (void) addItem:(TabBarItem*) item;
- (void) selectItem:(NSInteger) itemIndex;
- (void) show; - (void) show;
- (void) hide; - (void) hide;

View File

@ -11,14 +11,11 @@
#import "TabBarPickerSubItemsView.h" #import "TabBarPickerSubItemsView.h"
#import "MMCPSScrollView.h" #import "MMCPSScrollView.h"
#import <UIView-Overlay/UIView+Overlay.h> #import <UIView-Overlay/UIView+Overlay.h>
#import "NSString+HexColor.h"
#define DEFAULT_SUB_ITEMS_PER_ROW 2
#define DEFAULT_SUB_ITEM_HEIGHT 44
@interface TabBarPicker() <TabBarPickerSubItemsViewDelegate,TabBarItemDelegate> @interface TabBarPicker() <TabBarPickerSubItemsViewDelegate,TabBarItemDelegate>
@property (nonatomic) UIDeviceOrientation orientation; @property (nonatomic) UIDeviceOrientation orientation;
@property (nonatomic) NSUInteger subItemRows;
@property (nonatomic, strong) NSMutableArray *subItemSelectors; @property (nonatomic, strong) NSMutableArray *subItemSelectors;
@property (nonatomic, strong) NSMutableArray *subItemSelectorsConstraints; @property (nonatomic, strong) NSMutableArray *subItemSelectorsConstraints;
@property (nonatomic) BOOL isShow; @property (nonatomic) BOOL isShow;
@ -35,42 +32,29 @@
- (instancetype) initWithTabBarItems:(NSArray *) items forPosition:(TabBarPickerPosition) position { - (instancetype) initWithTabBarItems:(NSArray *) items forPosition:(TabBarPickerPosition) position {
return [self initWithTabBarItems:items withTabBarSize:CGSizeZero forPosition:position andNSLayoutRelation:NSLayoutRelationEqual subItemsPerRow:DEFAULT_SUB_ITEMS_PER_ROW subItemHeight:DEFAULT_SUB_ITEM_HEIGHT]; return [self initWithTabBarItems:items withTabBarSize:CGSizeZero forPosition:position andNSLayoutRelation:NSLayoutRelationEqual];
} }
- (instancetype) initWithTabBarItems:(NSArray *) items forPosition:(TabBarPickerPosition) position andNSLayoutRelation:(NSLayoutRelation) relation { - (instancetype) initWithTabBarItems:(NSArray *) items forPosition:(TabBarPickerPosition) position andNSLayoutRelation:(NSLayoutRelation) relation {
return [self initWithTabBarItems:items withTabBarSize:CGSizeZero forPosition:position andNSLayoutRelation:relation subItemsPerRow:DEFAULT_SUB_ITEMS_PER_ROW subItemHeight:DEFAULT_SUB_ITEM_HEIGHT]; return [self initWithTabBarItems:items withTabBarSize:CGSizeZero forPosition:position andNSLayoutRelation:relation];
} }
- (instancetype) initWithTabBarItems:(NSArray *) items withTabBarSize:(CGSize) size forPosition:(TabBarPickerPosition) position andNSLayoutRelation:(NSLayoutRelation) relation { - (instancetype) initWithTabBarItems:(NSArray*) items withTabBarSize:(CGSize) size forPosition:(TabBarPickerPosition) position andNSLayoutRelation:(NSLayoutRelation) relation {
return [self initWithTabBarItems:items withTabBarSize:size forPosition:position andNSLayoutRelation:relation subItemsPerRow:DEFAULT_SUB_ITEMS_PER_ROW subItemHeight:DEFAULT_SUB_ITEM_HEIGHT];
}
- (instancetype) initWithTabBarItems:(NSArray*) items withTabBarSize:(CGSize) size forPosition:(TabBarPickerPosition) position andNSLayoutRelation:(NSLayoutRelation) relation subItemsPerRow:(NSUInteger) subItemsPerRow {
return [self initWithTabBarItems:items withTabBarSize:size forPosition:position andNSLayoutRelation:relation subItemsPerRow:DEFAULT_SUB_ITEMS_PER_ROW subItemHeight:DEFAULT_SUB_ITEM_HEIGHT];
}
- (instancetype) initWithTabBarItems:(NSArray*) items withTabBarSize:(CGSize) size forPosition:(TabBarPickerPosition) position andNSLayoutRelation:(NSLayoutRelation) relation subItemsPerRow:(NSUInteger) subItemsPerRow subItemHeight:(CGFloat) subItemHeight {
self = [self initForAutoLayout]; self = [self initForAutoLayout];
if (self) { if (self) {
_subItemPerRow = subItemsPerRow;
_itemSpacing = 10; _itemSpacing = 10;
_layoutRelation = relation; _layoutRelation = relation;
_subItemHeight = subItemHeight;
_position = position; _position = position;
_dimWhenShow = YES; _dimWhenShow = YES;
_subItemSelectors = [[NSMutableArray alloc] init]; _subItemSelectors = [[NSMutableArray alloc] init];
_tabBarItemsConstraints = [[NSMutableArray alloc] init]; _tabBarItemsConstraints = [[NSMutableArray alloc] init];
_subItemSelectorsConstraints = [[NSMutableArray alloc] init]; _subItemSelectorsConstraints = [[NSMutableArray alloc] init];
_dimColor = [[UIColor blackColor] colorWithAlphaComponent: 0.5]; _dimColor = [[@"333333" colorFromHex] colorWithAlphaComponent: 0.5];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
@ -104,7 +88,7 @@
if ([_tabBarItems count] > 0) { if ([_tabBarItems count] > 0) {
int i = 0; int i = 0;
for (TabBarItem *item in _tabBarItems) { for (TabBarItem *item in _tabBarItems) {
TabBarPickerSubItemsView *subItemSelector = [[TabBarPickerSubItemsView alloc] initWithTabBarItem:item andsubItemsPerRow:_subItemPerRow]; TabBarPickerSubItemsView *subItemSelector = [[TabBarPickerSubItemsView alloc] init];
[subItemSelector setDelegate:self]; [subItemSelector setDelegate:self];
switch (i) { switch (i) {
case 0: case 0:
@ -122,7 +106,9 @@
[subItemSelector setBackgroundColor:[UIColor yellowColor]]; [subItemSelector setBackgroundColor:[UIColor yellowColor]];
} }
break; break;
default: default:{
[subItemSelector setBackgroundColor:[UIColor blueColor]];
}
break; break;
} }
i++; i++;
@ -254,6 +240,14 @@
} }
} }
- (void) selectItem:(NSInteger) itemIndex {
if ([_tabBarItems count] > itemIndex) {
[(TabBarItem*)[_tabBarItems objectAtIndex:itemIndex] setHighlighted:YES];
}
[self show];
}
- (void) show { - (void) show {
if (!_isShow) { if (!_isShow) {

View File

@ -11,6 +11,14 @@
@class TabBarPickerSubItemsView; @class TabBarPickerSubItemsView;
typedef NS_ENUM(NSInteger, TabBarPickerSubItemsViewType) {
// Informational
TabBarPickerSubItemsViewTypeData,
TabBarPickerSubItemsViewTypeString,
TabBarPickerSubItemsViewTypeButtons,
TabBarPickerSubItemsViewTypeCheckBox
};
@protocol TabBarPickerSubItemsViewDelegate <NSObject> @protocol TabBarPickerSubItemsViewDelegate <NSObject>
@required @required
@ -21,24 +29,10 @@
@interface TabBarPickerSubItemsView : UIView @interface TabBarPickerSubItemsView : UIView
/**
* <#Description#>
*/
@property (nonatomic, strong) NSMutableArray *subItemsArray;
/** /**
* <#Description#> * <#Description#>
*/ */
@property (nonatomic, assign) id<TabBarPickerSubItemsViewDelegate> delegate; @property (nonatomic, assign) id<TabBarPickerSubItemsViewDelegate> delegate;
/**
* <#Description#>
*
* @param items <#items description#>
* @param itemsPerRow <#itemsPerRow description#>
*
* @return <#return value description#>
*/
- (instancetype) initWithTabBarItem:(TabBarItem *) item andsubItemsPerRow:(NSUInteger) itemsPerRow;
@end @end

View File

@ -9,30 +9,22 @@
#import "TabBarPickerSubItemsView.h" #import "TabBarPickerSubItemsView.h"
#import <PureLayout/PureLayout.h> #import <PureLayout/PureLayout.h>
#define DEFAULT_ITEM_HEIGHT 44
@interface TabBarPickerSubItemsView() @interface TabBarPickerSubItemsView()
@property (nonatomic) NSUInteger itemsPerRow;
@property (nonatomic) CGFloat itemHeight;
@property (nonatomic) NSUInteger rows;
@property (nonatomic, assign) BOOL didSetupConstraints; @property (nonatomic, assign) BOOL didSetupConstraints;
@property (nonatomic) TabBarPickerSubItemsViewType type;
@property (nonatomic, strong) NSMutableArray *elementsArray;
@end @end
@implementation TabBarPickerSubItemsView @implementation TabBarPickerSubItemsView
- (instancetype) initWithTabBarItem:(TabBarItem *) item andsubItemsPerRow:(NSUInteger) itemsPerRow { - (instancetype) initWithType:(TabBarPickerSubItemsViewType) type andElements:(NSArray*) elements {
self = [self initForAutoLayout]; self = [self initForAutoLayout];
if (self) { if (self) {
_itemsPerRow = itemsPerRow; _type = type;
_subItemsArray = [[NSMutableArray alloc] initWithArray:[item subItems]]; _elementsArray = [[NSMutableArray alloc] initWithArray:elements];
_itemHeight = DEFAULT_ITEM_HEIGHT;
_rows = 0;
_rows = ceil(([_subItemsArray count]/_itemsPerRow));
} }
[self updateConstraintsIfNeeded]; [self updateConstraintsIfNeeded];
@ -43,21 +35,11 @@
- (void) layoutSubviews { - (void) layoutSubviews {
/*if ([self.constraints count] > 0) {
[NSLayoutConstraint deactivateConstraints:self.constraints];
for (TabBarItem *item in _itemsArray) {
for (TabBarSubItem *subItem in item.subItems) {
[subItem.constraints autoRemoveConstraints];
}
}
}*/
if (!_didSetupConstraints) { if (!_didSetupConstraints) {
//[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:-(_rows*_itemHeight)];
[self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:NSLayoutRelationEqual]; [self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:NSLayoutRelationEqual];
[self autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self.superview withOffset:0 relation:NSLayoutRelationEqual]; [self autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self.superview withOffset:0 relation:NSLayoutRelationEqual];
_didSetupConstraints = YES; _didSetupConstraints = YES;
} }
} }