1.
使用自定义方式定义tabbarItem
UITabBarItem *item1 = [[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemFavoritestag:1];
item1.badgeValue= @"item1";
homeVC.tabBarItem= item1;
UITabBarItem *item2 = [[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarkstag:2];
item2.badgeValue= @"haha";
UITabBarItem *item1 = [[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemFavoritestag:1];
item1.badgeValue= @"item1";
homeVC.tabBarItem= item1;
UITabBarItem *item2 = [[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarkstag:2];
item2.badgeValue= @"haha";
messageVC.tabBarItem = item2;
2.设置tabbar的背景颜色
tabCtrl.tabBar.barTintColor = [UIColor cyanColor];
3.设置选中图片的颜色
tabCtrl.tabBar.tintColor=
[UIColorcyanColor];
4.设置选中item后,显示在此item下面的图片
tabCtrl.tabBar.selectionIndicatorImage = [UIImageimageNamed:@"选中.png"];
5.隐藏自己的tabbarView
self.tabBar.hidden
= true;
6.创建选中视图
UIImageView *selectedView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,53,45)];
selectedView.tag= 100;
UIImageView *selectedView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,53,45)];
selectedView.tag= 100;
selectedView.image = [UIImageimageNamed:@"选中.png"];
7.创建标签栏的5个按钮
for(inti
= 0; i <
5; i++) {
UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeCustom];
btn.tag= 200 + i;
btn.frame= CGRectMake(scrrenWidth /5 * i, 0, scrrenWidth / 5, 49);
[btn addTarget:selfaction:@selector(btnClick:)forControlEvents:UIControlEventTouchUpInside];
NSString *imgName = [NSStringstringWithFormat:@"%d.png", i + 1];
[btn setImage:[UIImageimageNamed:imgName]forState:UIControlStateNormal];
UIButton *btn = [UIButtonbuttonWithType:UIButtonTypeCustom];
btn.tag= 200 + i;
btn.frame= CGRectMake(scrrenWidth /5 * i, 0, scrrenWidth / 5, 49);
[btn addTarget:selfaction:@selector(btnClick:)forControlEvents:UIControlEventTouchUpInside];
NSString *imgName = [NSStringstringWithFormat:@"%d.png", i + 1];
[btn setImage:[UIImageimageNamed:imgName]forState:UIControlStateNormal];
[_tabbarViewaddSubview:btn];
//设置选中图片中心与btn图片中心相同
if
(i ==
0) {
selectedView.center= btn.center;
}
selectedView.center= btn.center;
}
}
- (void)btnClick:(UIButton*)btn
{
//设置选择的控制器
self.selectedIndex= btn.tag- 200;
UIView *selectedView = [_tabbarViewviewWithTag:100];
[UIViewanimateWithDuration:0.3
animations:^{
selectedView.center= btn.center;
{
//设置选择的控制器
self.selectedIndex= btn.tag- 200;
UIView *selectedView = [_tabbarViewviewWithTag:100];
[UIViewanimateWithDuration:0.3
animations:^{
selectedView.center= btn.center;
}];
}
8.- (void)_initViewControllers
{
//三级控制器
HomeViewController *homeVC = [[HomeViewControlleralloc]init];
MessageViewController *messageVC = [[MessageViewControlleralloc]init];
SearchViewController *searchVC = [[SearchViewControlleralloc]init];
SettingViewController *settingVC = [[SettingViewControlleralloc]init];
MoreViewController *moreVC = [[MoreViewControlleralloc]init];
NSArray *viewControllers =@[homeVC, messageVC, searchVC, settingVC, moreVC];
NSMutableArray *navs = [NSMutableArrayarray];
//二级控制器
for (inti = 0; i < viewControllers.count; i ++) {
UINavigationController *nav = [[UINavigationControlleralloc]initWithRootViewController:viewControllers[i]];
nav.delegate= self;
[navs addObject:nav];
}
//一级控制器
self.viewControllers= navs;
HomeViewController *homeVC = [[HomeViewControlleralloc]init];
MessageViewController *messageVC = [[MessageViewControlleralloc]init];
SearchViewController *searchVC = [[SearchViewControlleralloc]init];
SettingViewController *settingVC = [[SettingViewControlleralloc]init];
MoreViewController *moreVC = [[MoreViewControlleralloc]init];
NSArray *viewControllers =@[homeVC, messageVC, searchVC, settingVC, moreVC];
NSMutableArray *navs = [NSMutableArrayarray];
//二级控制器
for (inti = 0; i < viewControllers.count; i ++) {
UINavigationController *nav = [[UINavigationControlleralloc]initWithRootViewController:viewControllers[i]];
nav.delegate= self;
[navs addObject:nav];
}
//一级控制器
self.viewControllers= navs;
}
本文详细介绍了如何自定义iOS与Android应用的Tab Bar界面,包括定义Tab Bar Item、设置背景颜色、选中图片颜色、隐藏Tab Bar View等操作,并提供了创建选中视图、设置标签栏按钮等功能。
3234

被折叠的 条评论
为什么被折叠?



