【问题标题】:on top tabbar controller or segmented在顶部标签栏控制器或分段
【发布时间】:2012-01-09 10:01:45
【问题描述】:

伙计们,我一直在想,目前我正在学习开发应用程序。我在 ipad 上看到一个 CNBC 应用程序,看起来像这里的图片:(抱歉,新用户不能直接发布图片 D:)

http://images.thoughtsmedia.com/resizer/thumbs/size/600/at/auto/1291813093.usr105634.jpg

我的问题是,应用顶部的那两个栏是什么?(带有市场和指数的栏)

它是一个标签栏控制器吗?如果是我们如何将它放在应用程序的顶部而不是像通常那样放在底部,我们如何在标签栏内有另一个标签栏???

感谢您的帮助,并为我的英语不好感到抱歉:3

【问题讨论】:

  • 您可以在不使用标签栏控制器的情况下构建它。更好的是,在 ios5 上您可以定义自己的容器视图控制器。
  • 我认为,它不是标签栏控制器。它是添加了自定义 Uibuttons 的自定义视图。
  • 我自己的容器视图控制器???老实说,我对此还是很陌生,所以我可能更喜欢其他解决方案而不是制作自己的自定义容器>。

标签: iphone objective-c ios xcode tabs


【解决方案1】:

好的,我已经找到了解决方案,到目前为止我已经尝试过自定义标签栏和分段控制器,但我发现它们都有风险且太复杂

所以我用简单的按钮做了一个小实验

这里是主要思想

首先,我设置了一个工具栏,并给它一个背景

-在 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;

-在 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;
}

所以主要思想是通过使用工具栏创建一个假标签栏,将 UIButton(s) 分配给工具栏作为假 tabbaritem,并为每个按钮提供机制,稍后将切换您的视图控制器(您必须首先分配视图控制器实现文件)

这对我来说效果很好,只是不要忘记设置视图控制器框架 Y 点 +(工具栏高度),否则它稍后会覆盖工具栏

:)

【讨论】:

    猜你喜欢
    • 2012-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 1970-01-01
    • 2014-06-11
    相关资源
    最近更新 更多