1. 程式人生 > >iOS 刪除系統自帶的tabbar

iOS 刪除系統自帶的tabbar

一、刪除系統自帶的tabbar

在開發中,我們時常會需要自己定義tabbar,使用自定義tabbar時,返回或者跳轉時會遇到tabbar重影的現象,這個時候我們需要將系統的tabbar

// 實現navigationController的代理方法
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    // 刪除系統自帶的tabBarButton
for (UIView *tabBar in self.tabBarController.tabBar.subviews) { if ([tabBar isKindOfClass:NSClassFromString(@"UITabBarButton")]) { [tabBar removeFromSuperview]; } } }

二、設定自定義tabbar的選中效果

MainTabBarViewController * tabBarController = (MainTabBarViewController *)self.navigationController
.tabBarController; tabBarController.selectedIndex = 0; tabBarController.customTabBar.selectedButton.selected = NO; for (UIView *child in tabBarController.customTabBar.subviews) { if ([child isKindOfClass:[MainTabBarButton class]]) { if (child.tag == 0) { tabBarController.customTabBar
.selectedButton = (MainTabBarButton *)child; tabBarController.customTabBar.selectedButton.selected = YES; } } }