第一步:隐藏TabBar :
self.tabBar.hidden = YES;
第二步: 设置TabBar的背景图,即按钮和文本元素
UIImageView *tarBarView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 431, 320, 49)]; tarBarView.userInteractionEnabled = YES; tarBarView.image = [UIImage imageNamed:@"tabbar_background"]; [self.view addSubview:tarBarView]; [tarBarView release];
//添加按钮 float coordinax = 0; for (int index = 0 ; index <5 ; index ++) { UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.tag = index; button.frame = CGRectMake(coordinax, 431, 64, 49); NSString *imageName = [NSString stringWithFormat:@"%d",index+1]; [button setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal]; [button addTarget:self action:@selector(changeViewController:) forControlEvents:UIControlEventTouchUpInside]; [tarBarView addSubview:button]; coordinax +=64; }
//按钮调用的方法 -(void)changeViewController:(id) sender { UIButton *button = (UIButton *) sender; self.selectedIndex = button.tag; //使用self.selectedIndex来区别点击的哪个按钮 switch (self.selectedIndex) { case 0: //执行的操作 调到某个界面 break; ... default: break; } }