IOS主页菜单通用代码

#pragma mark ViewCtrls
-(void)initViewCtrls
{
    HomeViewController *home = [[HomeViewController alloc] init];
    MessageViewController *msg = [[MessageViewController alloc] init];
    ProfileViewController *profile = [[ProfileViewController alloc] init];
    DiscoverViewController *discover = [[DiscoverViewController alloc] init];
    MoreViewController *more = [[MoreViewController alloc] init];
    
    NSArray *ctrls = @[home, msg, discover, profile, more];
    
    [home release];
    [msg release];
    [profile release];
    [discover release];
    [more release];
    
    NSMutableArray *navCtrls = [[NSMutableArray alloc] initWithCapacity:[ctrls count]];
    for (UIViewController *viewCtrl in ctrls) {
        BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:viewCtrl];
        [navCtrls addObject:nav];
        [nav release];
    }
    
    self.viewControllers = navCtrls;
    [navCtrls release];
}

-(void)initTabbarView
{
    float itemWidth = kScreenWidth/5;
    
    _tabbarView = [[ThemeImgView alloc] initWithFrame:CGRectMake(0, kScreenHeight-49-20, kScreenWidth, 49)];
    _tabbarView.imgName = @"mask_navbar.png";
    _tabbarView.userInteractionEnabled = YES;
    [self.view addSubview:_tabbarView];
    [_tabbarView release];
    
    _selectImgView = [[ThemeImgView alloc] initWithFrame:CGRectMake(0, 4, itemWidth, 45)];
    _selectImgView.imgName = @"home_bottom_tab_arrow.png";
    [_tabbarView addSubview:_selectImgView];
    [_selectImgView release];
    
    NSArray *imgArr = @[@"home_tab_icon_1.png", @"home_tab_icon_2.png", @"home_tab_icon_3.png", @"home_tab_icon_4.png", @"home_tab_icon_5.png"];
    
    for (int i=0; i<imgArr.count; i++) {
        ThemeButton *btn = [ThemeButton buttonWithType:UIButtonTypeCustom];
        btn.showsTouchWhenHighlighted = YES;
        btn.tag = i;
        btn.frame = CGRectMake(i*itemWidth, 4, itemWidth, 45);
        btn.imgName = imgArr[i];
        [btn addTarget:self action:@selector(selectTabbar:) forControlEvents:UIControlEventTouchUpInside];
        [_tabbarView addSubview:btn];
    }
}

-(void)selectTabbar:(UIButton *)btn
{
    self.selectedIndex = btn.tag;
    
    [UIView animateWithDuration:0.2 animations:^{
        _selectImgView.center = btn.center;
    }];
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值