// mytabbar . h
#import
@class AppDelegate;
@interfacemytabbar :UITabBarController
{
AppDelegate *appDelegate;
NSMutableArray *arrayofButton;
BOOLisRotate ;
}
@property (nonatomic, retain) NSMutableArray *arrayofButton;
-(void ) tabBarAction : (UIButton*) sender;
-(void ) setFrameForPortrait ;
-(void ) setFrameForLandScap ;
@end
*******************
//mytabbar . m
*******************
#import mytabbar.h"
#import "myvc1.h"
#import "myvc2.h"
@implementationmytabbar
@synthesize arrayofButton;
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear : YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
appDelegate=( AppDelegate*) [[UIApplication sharedApplication] delegate];
self.tabBarController.delegate=self;
arrayofButton = [[NSMutableArray alloc] init];
self . view. autoresizesSubviews=YES;
self . view. autoresizingMask=UIViewAutoresizingFlexibleHeight||UIViewAutoresizingFlexibleWidth;
NSMutableArray *controllerarray=[[NSMutableArray alloc] init];
UIImageView *tabBarBG=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Toll_bar.png"]];
tabBarBG . frame=CGRectMake( 0, 0, 1024,50);
[self . tabBar addSubview : tabBarBG ];
myvc1 *loc=[[myvc1 alloc] initWithNibName:@"myvc1" bundle:nil];
UINavigationController *nav_loc=[[UINavigationController alloc] initWithRootViewController:loc];
[nav_locsetNavigationBarHidden : FALSE];
loc . tabBarItem . image=[ UIImage imageNamed: @"tabTempImage1.png"];
loc . tabBarItem . title=@"Locations";
[controllerarray addObject : loc];
[nav_loc release];
[loc release];
myvc2 *loc2=[[myvc1 alloc] initWithNibName:@"myvc1" bundle:nil];
UINavigationController *nav_loc2=[[UINavigationController alloc] initWithRootViewController:loc2];
[nav_loc2setNavigationBarHidden : FALSE];
loc2. tabBarItem . image=[ UIImage imageNamed: @"tabTempImage1.png"];
loc2. tabBarItem . title=@"Locations";
[controllerarray addObject:loc2];
[nav_loc2 release];
[loc2 release];
self . viewControllers=controllerarray;
[controllerarray release];
isRotate=NO;
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
[self . tabBar addSubview:btn1];
[btn1 setImage:[UIImage imageNamed:@"Tab0.png"] forState:UIControlStateNormal];
[btn1 setImage:[UIImage imageNamed:@"Tab0_s.png"] forState:UIControlStateSelected];
btn1.tag = 0;
btn1.frame = CGRectMake(0+109,0,110, 48);
[btn1 addTarget:self action:@selector(tabBarAction:) forControlEvents:UIControlEventTouchUpInside];
[arrayofButton addObject:btn1];
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
[self . tabBar addSubview:btn2];
[btn2 setImage:[UIImage imageNamed:@"Tab1.png"] forState:UIControlStateNormal];
[btn2 setImage:[UIImage imageNamed:@"Tab1_s.png"] forState:UIControlStateSelected];
//[btn2setTitle : @"Sosh" forState : UIControlStateNormal];
btn2. tag = 1;
btn2.frame = CGRectMake(219,0,110, 48);
[btn2 addTarget:self action:@selector(tabBarAction:) forControlEvents:UIControlEventTouchUpInside];
[arrayofButton addObject:btn2];
[btn2setSelected : YES];
self . selectedIndex=1;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
UIButton *b = [arrayofButton objectAtIndex:tabBarController.selectedIndex];
[self tabBarAction:b];
}
-(void) tabBarAction:(UIButton*)sender{
UIButton *btn = sender;
self . selectedIndex = btn . tag;
for (int i=0; i < [arrayofButton count]; i++) {
UIButton *b = [arrayofButton objectAtIndex:i];
[b setSelected : NO];
}
self.selectedIndex =0;
self.selectedIndex=btn.tag;
[btn setSelected : YES];
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ( interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown )
{ [self setFrameForPortrait];
}
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation==UIInterfaceOrientationLandscapeRight)
{
[self setFrameForLandScap ];
}
return YES;
}
-(void) setFrameForPortrait{
int temp=109;
NSLog( @"setFrameForPortrait=%f", self. tabBarController . tabBar . frame. origin. x);
//[self . tabBarController . tabBar setFrame : CGRectMake( 0, 0, 768, 50)];
for (int i=0; i < [arrayofButton count] ; i++)
{
UIButton *b = [arrayofButton objectAtIndex:i];
if ( i==0)
{
b. frame = CGRectMake( i+temp, 0, 110, 48);
} else {
b. frame = CGRectMake( i*110+temp, 0, 110, 48);
}
}
}
-(void) setFrameForLandScap{
CGRect cg=self. tabBarController . selectedViewController . view. frame;
NSLog( @"setFrameForLandScap=%@", NSStringFromCGRect( self. tabBarController . tabBar . frame));
//[self . tabBarController . tabBar setFrame : CGRectMake( 0, 0, 1024, 50)];
NSLog( @"%@", NSStringFromCGRect( cg ));
int temp=237;
for (int i=0; i < [arrayofButton count] ; i++) {
UIButton *b = [arrayofButton objectAtIndex:i];
if ( i==0)
{
b. frame = CGRectMake( i+temp, 0, 110, 48);
} else {
b. frame = CGRectMake( i*110+temp, 0, 110, 48);
}
}
}
@end
#import
@class AppDelegate;
@interface
{
BOOL
}
@property (nonatomic
-(
-(
-(
@end
*******************
//
*******************
#import mytabbar.h"
#import "myvc1.h"
#import "myvc2.h"
@implementation
@synthesize arrayofButton;
-(void)viewWillAppear:(BOOL)animated
{
[
}
- (void)viewDidLoad {
[
appDelegate=
self.tabBarController.delegate=self;
arrayofButton = [[NSMutableArray alloc] init];
NSMutableArray *controllerarray=[[NSMutableArray alloc] init];
UIImageView *tabBarBG=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Toll_bar.png"]];
[
myvc1 *loc=[[myvc1 alloc] initWithNibName:@"myvc1" bundle:nil];
UINavigationController *nav_loc=[[UINavigationController alloc] initWithRootViewController:loc];
[nav_loc
[
[nav_loc release];
[
myvc2 *loc2=[[myvc1 alloc] initWithNibName:@"myvc1" bundle:nil];
UINavigationController *nav_loc2=[[UINavigationController alloc] initWithRootViewController:loc2];
[nav_loc2
loc2
loc2
[
[nav_loc2 release];
[loc2 release];
[
isRotate=NO;
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
[
[btn1 setImage:[UIImage imageNamed:@"Tab0.png"] forState:UIControlStateNormal];
[btn1 setImage:[UIImage imageNamed:@"Tab0_s.png"] forState:UIControlStateSelected];
btn1.tag = 0;
btn1.frame = CGRectMake(0+109,0,110, 48);
[btn1 addTarget:self action:@selector(tabBarAction:) forControlEvents:UIControlEventTouchUpInside];
[
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
[
[btn2 setImage:[UIImage imageNamed:@"Tab1.png"] forState:UIControlStateNormal];
[btn2 setImage:[UIImage imageNamed:@"Tab1_s.png"] forState:UIControlStateSelected];
//[btn2
btn2
btn2.frame = CGRectMake(219,0,110, 48);
[btn2 addTarget:self action:@selector(tabBarAction:) forControlEvents:UIControlEventTouchUpInside];
[arrayofButton addObject:btn2];
[btn2
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
UIButton *b = [arrayofButton objectAtIndex:tabBarController.selectedIndex];
[self tabBarAction:b];
}
-(void) tabBarAction:(UIButton*)sender{
UIButton *b = [arrayofButton objectAtIndex:i];
[
}
self.selectedIndex =0;
self.selectedIndex=btn.tag;
[
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
{ [self setFrameForPortrait];
}
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation==UIInterfaceOrientationLandscapeRight)
{
[
}
return YES;
}
-(void) setFrameForPortrait{
int temp=109;
NSLog
//[
for (int i=0; i < [arrayofButton count] ; i++)
{
UIButton *b = [arrayofButton objectAtIndex:i];
{
}
}
}
-(void) setFrameForLandScap{
NSLog
//[
NSLog
UIButton *b = [arrayofButton objectAtIndex:i];
{
}
}
}
@end