【问题标题】:placing a Tabbar controller on top of viewcontroller在 viewcontroller 上放置一个 Tabbar 控制器
【发布时间】:2014-03-25 21:45:09
【问题描述】:

如何将 TABBAR 控件放置在视图控件的顶部。默认情况下它在底部。我如何将其放置..?

使用以下代码:

 UIImage* tabBarBackground = [UIImage imageNamed:@"footer-bg.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance]setSelectionIndicatorImage:[UIImage imageNamed:@"footer-hover-bg.png"]];

if(IS_IOS_7)
{
    [[appDelegate.tabBarController tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"footer-hover-bg.png"]];
    [[UITabBar appearance] setTintColor:[UIColor blackColor]];
}
appDelegate.tabBarController.tabBar.frame = CGRectMake(0, 20, 320, 50);
appDelegate.tabBarController.delegate=self;

UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, -20, 320, 600)];

viewControllers = [[NSMutableArray alloc] init];

MainViewController *view1 = [[MainViewController alloc] init];
UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:view1];
[viewControllers addObject:nav1];

ViewController1 *view2 = [[ViewController1 alloc] init];
UINavigationController *nav2=[[UINavigationController alloc]initWithRootViewController:view2];
[viewControllers addObject:nav2];

[appDelegate.tabBarController setViewControllers:viewControllers];

appDelegate.tabBarController.tabBarController.view.frame=CGRectMake(0, 0, 320, 480);
[view addSubview:appDelegate.tabBarController.view];

[self.view addSubview:view];

UITabBarItem *tabBarItem1 = [appDelegate.tabBarController.tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [appDelegate.tabBarController.tabBar.items objectAtIndex:1];


[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:[arraySelectedImages objectAtIndex:0]] withFinishedUnselectedImage:[UIImage imageNamed:[arrayUnselectedImages objectAtIndex:0]]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:[arraySelectedImages objectAtIndex:1]] withFinishedUnselectedImage:[UIImage imageNamed:[arrayUnselectedImages objectAtIndex:1]]];

我如何使用故事板做同样的事情?

【问题讨论】:

    标签: ios iphone uitabbarcontroller


    【解决方案1】:

    首先添加UIViewController,然后添加UITabBar,如果使用自动布局,则添加约束。

    别忘了连接代理。

    希望这会有所帮助。

    【讨论】:

    • 我使用了 UITabBarController 并为其添加了视图。我可以更改它的框架以便将其添加到上面。
    • 没有。如果你使用 UITabBarController 你将无法改变位置
    • 你能否给我使用故事板的 Tabbar 的示例链接。我找不到:(
    • 非常感谢 :)。如何将第一个视图控制器与 stroyboard 中的第一个 tabbaritem 连接起来?我无法加载视图控制器。
    猜你喜欢
    • 2017-07-13
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    • 2021-05-14
    • 2013-09-12
    相关资源
    最近更新 更多