简体   繁体   English

在顶部标签栏控制器上或分段

[英]on top tabbar controller or segmented

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:) 我在ipad上看到了一个CNBC应用,看起来像这里的图片:(对不起,新用户无法直接发布图片D :)

http://images.thoughtsmedia.com/resizer/thumbs/size/600/at/auto/1291813093.usr105634.jpg 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) 我的问题是,应用程序顶部的那两个条形是什么?(带有市场和索引的那个条形)

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??? 如果是这样,我们如何将其放置在应用程序顶部而不是通常的底部,以及如何在标签栏内放置另一个标签栏?

i appreciate your helps, and sorry for my bad english :3 我感谢您的帮助,并对我的英语不好: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 所以我用简单的按钮做了一点实验

here's the main idea 这是主要思想

first, i set up a toolbar, and give it a background 首先,我设置了一个工具栏,并为其提供了背景

-in viewController.h -在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 -在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;
}

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) 所以主要思想是通过使用工具栏创建伪造的选项卡,将UIButton作为伪造的tabbaritem分配给工具栏,并为每个按钮提供机制,以后会切换您的视图控制器(您必须先在实现文件中分配视图控制器)

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

:) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM