在顶部标签栏控制器上或分段 [英] on top tabbar controller or segmented

查看:60
本文介绍了在顶部标签栏控制器上或分段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直想知道,目前我正在学习开发应用程序.我在ipad上看到了一个CNBC应用,看起来像这里的图片:(对不起,新用户不能直接发布图片D:)

so guys, i've been wondering, currently i'm in the middle of learning on developing apps. i saw a CNBC apps at ipad that looks like the image here : (sorry, new user cant directly post image D:)

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

我的问题是,应用程序顶部的那两个条形是什么?(带有市场和索引的那一条)

my question is, what are those 2 bars on top of the app??(the one with markets, and indexes)

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

is it a tabbar controller?? if it is how do we put it on top of the app instead of at the bottom like it normally is, and how do we have another tabbar inside a tabbar???

感谢您的帮助,对于我的英语不好:3

i appreciate your helps, and sorry for my bad english :3

推荐答案

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

okay, i have found the solution to this, by far i've tried both customized tabbar and segmented controller, but i found both of them risky and too complicated

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

so i do a little experiment with simple button

这是主要思想

首先,我设置了一个工具栏,并为其提供了背景

first, i set up a toolbar, and give it a background

-在viewController.h中

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

-在viewController.m

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

所以主要思想是通过使用工具栏创建伪造的选项卡,将UIButton作为伪造的tabbaritem分配给工具栏,并为每个按钮提供机制,以后将切换您的视图控制器(您必须首先在以下位置分配视图控制器)实施文件)

so the main idea is creating a fake tabbar by using toolbar, assigning UIButton(s) to the toolbar as the fake tabbaritem, and giving mechanism to each button that later will switch your viewcontrollers (you have to alloc the viewcontrollers first at implementation file)

这对我来说效果很好,只是别忘了设置视图控制器框架的Y点+(工具栏高度),因为否则它将在以后覆盖工具栏

this works well for me, just dont forget to set the view controllers frame Y point +(toolbar Height) because otherwise it will cover the toolbar later

:)

这篇关于在顶部标签栏控制器上或分段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆