呵呵*


- (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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值