ITeye博客

呵呵*

peng13123 · 2014-11-10 19:26 · ⋯⋯ · 移动开发 · Markdown


- (void)viewDidLoad
{
    [super viewdidload];
    // Do any additional setup after loading the view.
    [self _initviewcontroller];
    [self _inittabbbarview];
}

- (void)didReceiveMemoryWarning
{
    [super didreceivememorywarning];
    // Dispose of any resources that can be recreated.
}

//初始化子控制器
-(void)_initViewController{
    HomeViewController *home = [[homeviewcontroller alloc]init];
    MsssageViewController *message = [[msssageviewcontroller alloc]init];
    ProfireViewController *profire = [[profireviewcontroller alloc]init];
    SquareViewController *square = [[squareviewcontroller alloc]init];
    MoreViewController *more = [[moreviewcontroller alloc]init];
    
    
    NSArray *views = @[home,message,profire,square,more];
    NSMutableArray *navViews=[nsmutablearray arraywithcapacity:5];
    for (UIViewController *viewController in views) {
        BaseNavigationController *nav = [[basenavigationcontroller alloc]initWithRootViewController:viewController];
        [navviews addobject:nav];
    }
    self.viewControllers = navViews;
}

//创建自定义tabbar
-(void)_initTabbbarView{
//    [uiscreen mainscreen].bounds.size.height  //物理高度
    _tabbarView =[[uiview alloc]initWithFrame:CGRectMake(0, ScreenH-49, 320, 49)];
    [_tabbarview setbackgroundcolor:[uicolor graycolor]];
    [self.view addsubview:_tabbarview];
    
    NSArray *background = @[@"tabbar_home",@"tabbar_message",@"tabbar_profile",@"tabbar_discover",@"tabbar_more"];
    NSArray *background_high = @[@"tabbar_home_highlighted",@"tabbar_message_highlighted",@"tabbar_profile_highlighted",@"tabbar_discover_highlighted",@"tabbar_more_highlighted"];
    NSArray *background_selected = @[@"tabbar_home_selected",@"tabbar_message_selected",@"tabbar_profile_selected",@"tabbar_discover_selected",@"tabbar_more_selected"];
    
    for (int i=0;i<background.count;i++) {
        NSString *backImage = background[i];
        NSString *backgImage_high = background_high[i];
        NSString *backImageSelected = background_selected[i];
        
        UIButton *btn = [uibutton buttonwithtype:uibuttontypecustom];
        btn.frame =CGRectMake((320/5-30)/2+(i*(320/5)), (49-30)/2, 30, 30);
        [btn setimage:[uiimage imagenamed:backimage] forState:UIControlStateNormal];
        [btn setimage:[uiimage imagenamed:backgimage_high] forState:UIControlStateHighlighted];
        [btn setimage:[uiimage imagenamed:backimageselected] forState:UIControlStateSelected];
        [btn settag:i];
        [btn addtarget:self action:@selector(selectedtab:) forcontrolevents:uicontroleventtouchupinside];
        
        [_tabbarview addsubview:btn];
    }
}

-(void)selectedTab:(UIButton *)sender{
    UIButton *btn =sender;
    self.selectedIndex=btn.tag;
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。