Skip to content

Instantly share code, notes, and snippets.

@MPiccinato
Created September 19, 2011 18:57
Show Gist options
  • Save MPiccinato/1227275 to your computer and use it in GitHub Desktop.
Save MPiccinato/1227275 to your computer and use it in GitHub Desktop.
SlidingTabsExample.m
@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
// 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