Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

iphone - 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:)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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)

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

:)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...