Created
September 19, 2011 18:57
-
-
Save MPiccinato/1227275 to your computer and use it in GitHub Desktop.
SlidingTabsExample.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation MainViewController | |
- (id)init { | |
if (self = [super init]) { | |
// The controllers | |
controller1 = [[UIViewController alloc] init]; | |
[self.view addSubview: controller1.view]; | |
controller1.view.hidden = NO; | |
controller2 = [[UIViewController alloc] init]; | |
[self.view addSubview: controller2.view]; | |
controller2.view.hidden = YES; | |
controller3 = [[UIViewController alloc] init]; | |
[self.view addSubview: controller3.view]; | |
controller3.view.hidden = YES; | |
// Sliding tabs | |
SlidingTabsControl* tabs = [[SlidingTabsControl alloc] initWithTabCount:3 delegate:self]; | |
[self.view addSubview:tabs]; | |
} | |
return self; | |
} | |
#pragma mark SlidingTabsControl Delegate | |
- (UILabel*) labelFor:(SlidingTabsControl*)slidingTabsControl atIndex:(NSUInteger)tabIndex | |
{ | |
UILabel* label = [[[UILabel alloc] init] autorelease]; | |
switch (tabIndex +1){ | |
case 1: | |
label.text = @"C 1"; | |
break; | |
case 2: | |
label.text = @"C 2"; | |
break; | |
case 3: | |
label.text = @"C 3"; | |
break; | |
} | |
return label; | |
} | |
- (void) touchUpInsideTabIndex:(NSUInteger)tabIndex | |
{ | |
// Hide all tab controllers | |
controller1.view.hidden = YES; | |
controller2.view.hidden = YES; | |
controller3.view.hidden = YES; | |
// Change to the new content | |
switch (tabIndex +1){ | |
case 1: | |
controller1.view.hidden = NO; | |
break; | |
case 2: | |
controller2.view.hidden = NO; | |
break; | |
case 3: | |
controller3.view.hidden = NO; | |
break; | |
} | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Libraries | |
#import "SlidingTabsControl.h" | |
@interface MainViewController : UIViewController <SlidingTabsControlDelegate> { | |
UIViewController *controller1; | |
UIViewController *controller2; | |
UIViewController *controller3; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment