Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging Custom tab bar postion in 2 tab view Controller
    text
    copied!<p>I Am using custom Tab bar with buttons.I have made custom tab bar at the top position.I have successfully made it.But I want tab bar position to be in the center for two view controller>how can i do it.Is it possible?? Here 's my code </p> <p>This is my custom tab bar.m file</p> <pre><code>-(void)addCustomElements { btn1 = [UIButton buttonWithType:UIButtonTypeCustom]; //Setup the button btn1.frame = CGRectMake(0, 264, 65, 40); // Set the frame (size and position) of the button) [btn1 setBackgroundColor:[UIColor darkGrayColor]]; [btn1.titleLabel setFont:[UIFont fontWithName:@"Helvetica Neue" size:16.0]]; [btn1 setTitle:@"Info" forState:UIControlStateNormal]; [btn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [btn1 setTag:0]; // Assign the button a "tag" so when our "click" event is called we know which button was pressed. [btn1 setSelected:true]; // Set this button as selected (we will select the others to false as we only want Tab 1 to be selected initially // Now we repeat the process for the other buttons btn2 = [UIButton buttonWithType:UIButtonTypeCustom]; //Setup the button btn2.frame = CGRectMake(64, 264, 65, 40); // Set the frame (size and position) of the button) [btn2 setBackgroundColor:[UIColor darkGrayColor]]; [btn2.titleLabel setFont:[UIFont fontWithName:@"Helvetica Neue" size:16.0]]; [btn2 setTitle:@"Book" forState:UIControlStateNormal]; [btn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [btn2 setTag:1]; // Assign the button a "tag" so when our "click" event is called we know which button was pressed. [btn2 setSelected:true]; btn3 = [UIButton buttonWithType:UIButtonTypeCustom]; //Setup the button btn3.frame = CGRectMake(128, 264, 65, 40); // Set the frame (size and position) of the button) [btn3 setBackgroundColor:[UIColor darkGrayColor]]; [btn3.titleLabel setFont:[UIFont fontWithName:@"Helvetica Neue" size:16.0]]; [btn3 setTitle:@"Menu" forState:UIControlStateNormal]; [btn3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [btn3 setTag:2]; // Assign the button a "tag" so when our "click" event is called we know which button was pressed. [btn3 setSelected:true]; btn4 = [UIButton buttonWithType:UIButtonTypeCustom]; //Setup the button btn4.frame = CGRectMake(193, 264, 65, 40); // Set the frame (size and position) of the button) [btn4.titleLabel setFont:[UIFont fontWithName:@"Helvetica Neue" size:16.0]]; [btn4 setBackgroundColor:[UIColor darkGrayColor]]; [btn4 setTitle:@"Reviews" forState:UIControlStateNormal]; [btn4 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [btn4 setTag:3]; // Assign the button a "tag" so when our "click" event is called we know which button was pressed. [btn4 setSelected:true]; btn5 = [UIButton buttonWithType:UIButtonTypeCustom]; //Setup the button btn5.frame = CGRectMake(258, 264, 65, 40); // Set the frame (size and position) of the button) [btn5.titleLabel setFont:[UIFont fontWithName:@"Helvetica Neue" size:16.0]]; [btn5 setBackgroundColor:[UIColor darkGrayColor]]; [btn5 setTitle:@"Map" forState:UIControlStateNormal]; [btn5 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [btn5 setTag:4]; // Assign the button a "tag" so when our "click" event is called we know which button was pressed. [btn5 setSelected:true]; // Add my new buttons to the view [self.view addSubview:btn1]; [self.view addSubview:btn2]; [self.view addSubview:btn3]; [self.view addSubview:btn4]; [self.view addSubview:btn5]; // Setup event handlers so that the buttonClicked method will respond to the touch up inside event. [btn1 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; [btn2 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; [btn3 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; [btn4 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; [btn5 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; } - (void)buttonClicked:(id)sender { int tagNum = [sender tag]; [self selectTab:tagNum]; } -(void)selectTab:(int)tabID { switch(tabID) { case 0: [btn1 setSelected:true]; [btn2 setSelected:false]; [btn3 setSelected:false]; [btn4 setSelected:false]; [btn5 setSelected:false]; break; case 1: [btn1 setSelected:false]; [btn2 setSelected:true]; [btn3 setSelected:false]; [btn4 setSelected:false]; [btn5 setSelected:false]; break; case 2: [btn1 setSelected:false]; [btn2 setSelected:false]; [btn3 setSelected:true]; [btn4 setSelected:false]; [btn5 setSelected:false]; break; case 3: [btn1 setSelected:false]; [btn2 setSelected:false]; [btn3 setSelected:false]; [btn4 setSelected:true]; [btn5 setSelected:false]; break; case 4: [btn1 setSelected:false]; [btn2 setSelected:false]; [btn3 setSelected:false]; [btn4 setSelected:false]; [btn5 setSelected:true]; break; } if (self.selectedIndex == tabID) { UINavigationController *navController = (UINavigationController *)[self selectedViewController]; [navController popToRootViewControllerAnimated:YES]; } else { self.selectedIndex = tabID; } } - (void)viewDidLoad { [super viewDidLoad]; [self hideExistingTabBar]; [self addCustomElements]; // Do any additional setup after loading the view. </code></pre> <p>}</p> <p>Please Help.Thanks In advance!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload