所以伙计们,我一直在想,目前我正在学习开发应用程序。我在ipad上看到了一个看起来像这里图像的CNBC应用程序:(对不起,新用户无法直接发布图像D:)
http://images.thoughtsmedia.com/resizer/thumbs/size/600/at/auto/1291813093.usr105634.jpg
我的问题是,应用程序顶部的那两个栏是什么?(有市场和索引的那个吧)
是tabbar控制器吗?如果它是我们如何把它放在应用程序的顶部而不是像往常一样在底部,我们如何在标签栏中有另一个标签栏???
我感谢你的帮助,对不起我的坏英语:3
答案 0 :(得分:0)
所以我用简单的按钮进行了一些实验
这是主要的想法
首先,我设置了一个工具栏,并给它一个背景
-in viewController.h
//adding my viewcontrollers
@class notLoggedHome;
@class LoggedInHome;
@class NABViewController;
//defining all the objects
@properties (nonatomic, strong) UIToolBar *mainToolBar;
@properties (nonatomic, strong) UIButton *toolBarBut1, *toolBarBut2, *toolBarBut3;
@properties (nonatomic, strong) UIImageView *logoImage;
@property (nonatomic, strong) notLoggedHome *viewNotLoggedHome;
@property (nonatomic, strong) LoggedInHome *viewLoggedInHome;
@property (nonatomic, strong) NABViewController *viewNAB;
@properties NSInteger lastTag;
-in viewController.m
@synthesize mainToolBar, toolBarBut1, toolBarBut2, toolBarBut3;
@synthesize logoImage, lastTag;
@synthesize viewNotLoggedHome, viewLoggedInHome, viewNAB;
-(void)viewDidLoad
{
lastTag = 100;
self.view.backgroundColor = [UIColor colorWithRed:21.0/255.0 green:21.0/255.0 blue:21.0/255.0 alpha:1];
//---
//---fakeTabBar set up===
viewNotLoggedHome = [[notLoggedHome alloc]init];
viewLoggedInHome = [[LoggedInHome alloc]init];
viewNAB = [[NABViewController alloc]init];
//creating the fakeTabBar
mainToolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)];
[mainToolBar setBackgroundImage:[UIImage imageNamed:@"menu_bar.jpg"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
//defining images
imgHome = [UIImage imageNamed:@"menu_home.png"];
imgHomeS = [UIImage imageNamed:@"menu_home_s.png"];
imgLogo = [UIImage imageNamed:@"menu_bar_logo_ep.png"];
UIImageView *logoImage = [[UIImageView alloc]initWithImage:imgLogo];
logoImage.frame = CGRectMake(0, 0, imgLogo.size.width, imgLogo.size.height);
//--button setting====
toolBarBut1 = [UIButton buttonWithType:UIButtonTypeInfoLight];
[toolBarBut1 setFrame:CGRectMake(imgLogo.size.width, 1, imgHome.size.width, imgHome.size.height)];
toolBarBut1.tag = 0;
toolBarBut1.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
[toolBarBut1 setImage:imgHome forState:UIControlStateNormal];
[toolBarBut1 setImage:imgHomeS forState:UIControlStateSelected];
[toolBarBut1 addTarget:self action:@selector(barPressed:) forControlEvents:UIControlEventTouchUpInside];
//do the same with the other 2 button
//---------------------
[mainToolBar addSubview:logoImage];
[mainToolBar addSubview:toolBarBut1];
//do the same with the other 2 button
[self.view addSubview:mainToolBar];
[super viewDidLoad];
}
-(void)barPressed:(id)sender
{
UIButton *button = (UIButton *)sender;
if(button.tag == 0 && button.tag != lastTag)
{
[viewNAB removeFromParentViewController];
[viewNotLoggedHome removeFromParentViewController];
[self.view addSubview:viewLoggedInHome.view];
button.selected = YES;
}
if(button.tag == 1 && button.tag != lastTag)
{
[viewNAB removeFromParentViewController];
[viewLoggedInHome removeFromParentViewController];
[self.view addSubview:viewNotLoggedHome.view];
button.selected = YES;
}
if(button.tag == 2 && button.tag != lastTag)
{
[viewLoggedInHome removeFromParentViewController];
[viewNotLoggedHome removeFromParentViewController];
[self.view addSubview:viewLoggedInHome.view];
button.selected = YES;
}
lastTag = button.tag;
}
所以主要的想法是使用工具栏创建一个虚假的tabbar,将UIButton作为假的tabbaritem分配给工具栏,并为每个按钮提供机制,稍后将切换你的viewcontrollers(你必须首先分配viewcontrollers)实施文件)
这对我很有用,只是不要忘记设置视图控制器框架Y点+(工具栏高度),否则它将覆盖工具栏以后
:)