push頁面時,可調用hidesBottomBarWhenPushed進行隱藏。
第一步,我們需要一些圖片:
各個選項的圖標和tabbar的背景圖片,最後還要一個透明的1x1像素的圖片。
第二步,新建一個工程,在工程內建一個繼承於UITabBarController的類。<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PGltZyBzcmM9"/uploadfile/Collfiles/20140329/2014032910514539.jpg" width="400" height="300" alt="\">
第三步,首先寫一個方法,返回一個UINavigationController
-(UINavigationController*) viewControllerWithTitle:(NSString*) title image:(UIImage*)image { UIViewController* viewController = [[UIViewController alloc] init]; viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image tag:0]; viewController.title = title; UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewController]; return nav; }
self.viewControllers = [NSArray arrayWithObjects: [self viewControllerWithTitle:@"1" image:IMG(@"1")], [self viewControllerWithTitle:@"2" image:IMG(@"2")], [self viewControllerWithTitle:nil image:nil], [self viewControllerWithTitle:@"3" image:IMG(@"3")], [self viewControllerWithTitle:@"4" image:IMG(@"4")], nil];
因為我們要在那個位置放一個自己的按鈕,繼續在viewDidLoad寫:
UIButton* button = [[UIButton alloc]initWithFrame:CGRectMake(0.0, 0.0, 65, 65)]; button.center = CGPointMake(160, 20); [button setBackgroundImage:IMG(@"add") forState:UIControlStateNormal]; [button addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside]; [self.tabBar addSubview:button];
然後設置背景圖片:
[self.tabBar setBackgroundImage:IMG(@"tabbarbg")];運行之後是這樣的:
會發現按鈕上面有一條橫線,然後再設置這個陰影運行後就沒有人發現你猥瑣的行徑。
[self.tabBar setShadowImage:IMG(@"transparent")];最後效果圖(iOS7和iOS6):
源碼下載