如何在我的所有视图底部添加常见的UIButton而不是iphone中的tabsview控制器?

时间:2012-12-17 06:47:08

标签: iphone ios uiwindow

我想将UIbutton放在底部,这应该显示在我的所有视图上,例如tabBar和onclick UIButton我要打开菜单视图,如何实现此功能,我为此尝试了很多,也有很多谷歌搜索它,但没有提到正确实现这一点的方法,所以请建议我实现这个的正确方法

This image contain at bottom one 'Team' button, onclick of that 'Team' the menu view should open look next screen shot for that

The black view contaning menu should open

2 个答案:

答案 0 :(得分:2)

我之前通过在Appdelegate类中添加一个按钮来完成此操作。我不知道这是否是正确的方法,但它正在发挥作用。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    viewController = [[SUSAViewController alloc] initWithNibName:@"SUSAViewController" bundle:nil];

    nav=[[UINavigationController alloc]initWithRootViewController:viewController];
    self.window.rootViewController = nav;

    UIButton *mybtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    mybtn.frame=CGRectMake(40, 200, 200, 200);
    [mybtn setTitle:@"My Button" forState:UIControlStateNormal];

    [nav.view addSubview:mybtn];

    [self.window makeKeyAndVisible];

    return YES;
}

如果您未使用NavigationController,则只需添加[self.window addSubview:mybtn]; 希望它对你有用。

答案 1 :(得分:0)

您是否尝试过创建仅包含该按钮及其菜单项的BaseViewController?

然后,如果您让所有视图控制器都从该BaseViewController继承,那么所有View控制器都将拥有该按钮。

// import your custom menu view
#import "CustomMenuView.h"

@interface BaseViewController : UIViewController
{
    UIButton *btnMenu;
    CustomMenuView *customMenu;
}

@end 

...

// Now tell your other view controllers to inherit from the base view controller
#import "BaseViewController.h"

@interface YourOtherViewController: BaseViewController
{

}

@end

使用继承,您的所有视图控制器现在应该具有该按钮和菜单。