This commit is contained in:
Giuseppe Nucifora 2015-07-21 10:44:52 +02:00
parent 603962375e
commit 61604557dd
4 changed files with 31 additions and 26 deletions

View File

@ -628,10 +628,10 @@
4E0DA1B3F943CB5DD84434E2 /* Classes */ = {
isa = PBXGroup;
children = (
948796D629A2FE463CD40F14 /* TabBarItem.h */,
6D0486D2A6CC5159ED6C3FA5 /* TabBarItem.m */,
6EBFE41004AD256533049528 /* TabBarPicker.h */,
66C7B75EB841D53F0EC483E0 /* TabBarPicker.m */,
948796D629A2FE463CD40F14 /* TabBarItem.h */,
6D0486D2A6CC5159ED6C3FA5 /* TabBarItem.m */,
038E63B1DBCA0584644ED157 /* TabBarPickerSubItemsView.h */,
13660ECE3ACE682AFF3887AC /* TabBarPickerSubItemsView.m */,
489D9E1E1C7A2D5F8BC9F84C /* TabBarSubItem.h */,

View File

@ -58,11 +58,16 @@
[allergen setImage:[UIImage imageNamed:@"allergen_off"]];
[allergen setSelectedImage:[UIImage imageNamed:@"allergen_on"]];
tabbar = [[TabBarPicker alloc] initWithTabBarItems:@[location,calendar,type,price,allergen] forPosition:TabBarPickerPositionBottom];
TabBarItem *allergen2 = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
[allergen2 setItemName:@"Allergen"];
[allergen2 setImage:[UIImage imageNamed:@"allergen_off"]];
[allergen2 setSelectedImage:[UIImage imageNamed:@"allergen_on"]];
tabbar = [[TabBarPicker alloc] initWithTabBarItems:@[location,calendar,type,price,allergen] forPosition:TabBarPickerPositionRight];
[tabbar setItemSpacing:2];
[tabbar setBackgroundColor:[UIColor whiteColor]];
[tabbar addItem:allergen];
[tabbar addItem:allergen2];
}
return self;
}
@ -74,6 +79,8 @@
[contentView addSubview:tabbar];
self.view = contentView;
[self.view setNeedsUpdateConstraints];
}
- (void)viewDidLoad
@ -82,7 +89,6 @@
//[self.view setBackgroundColor:[UIColor lightGrayColor]];
// Do any additional setup after loading the view, typically from a nib.
[super updateViewConstraints];
}
- (void) viewDidAppear:(BOOL)animated {
@ -100,7 +106,9 @@
[allergen setImage:[UIImage imageNamed:@"allergen_off"]];
[allergen setSelectedImage:[UIImage imageNamed:@"allergen_on"]];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[tabbar addItem:allergen];
});
}
- (void)didReceiveMemoryWarning

View File

@ -28,6 +28,7 @@
_orientation = [[UIDevice currentDevice] orientation];
_itemButton = [[UIButton alloc] initForAutoLayout];
[_itemButton setBackgroundColor:[UIColor whiteColor]];
[self addSubview:_itemButton];
@ -44,7 +45,8 @@
- (void) layoutSubviews {
[_itemButton autoPinEdgesToSuperviewMargins];
//[_itemButton autoPinEdgesToSuperviewMargins];
[_itemButton autoCenterInSuperview];
}

View File

@ -60,13 +60,22 @@
}
}
[self setNeedsUpdateConstraints];
[self updateConstraintsIfNeeded];
return self;
}
- (void) layoutSubviews {
if ([self.constraints count] > 0) {
[NSLayoutConstraint deactivateConstraints:self.constraints];
for (TabBarItem *item in _tabBarItems) {
[item.constraints autoRemoveConstraints];
}
}
switch (_position) {
case TabBarPickerPositionLeft:{
[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:20];
@ -111,6 +120,7 @@
break;
case TabBarPickerPositionBottom:
default:{
[self autoPinEdgeToSuperviewMargin:ALEdgeBottom];
[self autoSetDimension:ALDimensionHeight toSize:44];
[self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:_layoutRelation];
@ -118,26 +128,20 @@
[_tabBarItems autoSetViewsDimension:ALDimensionHeight toSize:44.0];
[_tabBarItems autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:0 insetSpacing:YES matchedSizes:YES];
[[_tabBarItems firstObject] autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
[_tabBarItems autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:_itemSpacing insetSpacing:YES matchedSizes:YES];
}
break;
}
[self updateConstraints];
[self updateConstraintsIfNeeded];
}
- (void) setPosition:(TabBarPickerPosition)position {
_position = position;
if (self.superview) {
[self removeConstraints:self.constraints];
for (TabBarItem *item in _tabBarItems) {
[item removeConstraints:item.constraints];
}
[self layoutSubviews];
}
}
@ -145,15 +149,11 @@
- (void)deviceOrientationDidChange:(NSNotification *)notification {
//Obtain current device orientation
_orientation = [[UIDevice currentDevice] orientation];
[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];
@ -162,11 +162,6 @@
if (self.superview) {
[self removeConstraints:self.constraints];
for (TabBarItem *item in _tabBarItems) {
[item removeConstraints:item.constraints];
}
[self layoutSubviews];
}
}