OC_使用系统的tabBar,自定义tabBarItem

建立自己的TabBarController,继承UITabBarController


Paste_Image.png

MyTabBarController.m

- (void)viewDidLoad {  
    [super viewDidLoad];  
    // 使用系统自带的tabBar注意这两个函数的先后顺序  
    [self createViewControllers];  
    [self createMyTabBarItem];  
}

- (void)btnClick:(UIButton *)sender {  
    // 设置视图切换  
    NSInteger index = sender.tag-100;  
    self.selectedIndex = index;  
  
    for (UIView * view in self.tabBar.subviews) {  
        // 要判断view的类型  
        if ([view isKindOfClass:[UIButton class]]) {  
            UIButton * btn = (UIButton *)view;  
            if (btn.tag == sender.tag) {  
                btn.selected = YES;  
            } else {  
                btn.selected = NO;  
            }  
        }  
    }  
    /* 
     self.tabBar.subviews.count = 5; 
     self.tabBar.subviews: 
     ( 
     "<_UITabBarBackgroundView: 0x7fc513ff48c0; frame = (0 0; 375 49); autoresize = W; userInteractionEnabled = NO; layer = >", 
     ">", 
     ">", 
     ">", 
     ">" 
     ) 
     */  
} 

- (void)createViewControllers {  
    NSMutableArray * viewControllers = [[NSMutableArray alloc] init];  
//    NSArray * classNames = @[@"MovieViewController",@"CinemaViewController",@"SettingViewController"];  
//    for (NSInteger i=0; i

你可能感兴趣的:(OC_使用系统的tabBar,自定义tabBarItem)