zoukankan      html  css  js  c++  java
  • iPhone中如何自定义tabbar

    基本思路是这样的:
    1. 创建一个RootViewController,它作为delegate加载的第一个controller
    2. RootViewController的上半部分加载TabbarController,下半部分是自己画的控件,它用来控制Tabbar Controller加载哪个controller的
    3. 把Tabbar controller的Tabbar给hide掉
    4. RootViewController的下半部分是自己画的Tabbar,想怎么画就怎么画
    大家看我的截图,上面是tabbar controller,它的tabbar已经给隐藏了。
    下面是我自己画的自定义tabbar,还很粗糙,最左边的按钮已经可以控制tabbar的切换了。

    如何隐藏tabbar控件:
    首先要customize UITabBarController,其头文件定义为:

    #import <UIKit/UIKit.h>



    @interface CustomTabbar : UITabBarController {

    IBOutlet UITabBar *tabBar1;

    }

    @property(nonatomic, retain) UITabBar *tabBar1;

    -(void) hideExistingTabBar;

    @end


    在实现文件中加入:

    - (void)hideExistingTabBar

    {

    for(UIView *view in self.view.subviews)

    {

    if([view isKindOfClass:[UITabBar class]])

    {

    view.hidden = YES;

    break;

    }

    }

    }


    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

    - (void)viewDidLoad {

        [super viewDidLoad];

    [self hideExistingTabBar];



    让application delegate默认启动RootViewController

    @interface MyTabbarAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {

        UIWindow *window;

        RootViewController *rootController;

    }


    @property (nonatomic, retain) IBOutlet UIWindow *window;

    @property (nonatomic, retain) IBOutlet RootViewController *rootController;

    实现文件代码:

    @implementation MyTabbarAppDelegate


    @synthesize window;

    @synthesize rootController;



    - (void)applicationDidFinishLaunching:(UIApplication *)application {

        

        // Add the tab bar controller's current view as a subview of the window

        [window addSubview:rootController.view];

    }


    RootViewController如何加载tabbar controller:

    @class CustomTabbar;


    @interface RootViewController : UIViewController {

    CustomTabbar *tabbarController;

    }


    @property (nonatomic, retain) IBOutlet CustomTabbar *tabbarController;

    - (IBAction) clikcOnFirst:(id)sender;


    @end

    实现代码:

    - (void)viewDidLoad {

    [tabbarController.view setFrame:CGRectMake(0, 0, 300, 300)];

    [self.view insertSubview:tabbarController.view atIndex:0];    


        [super viewDidLoad];

    }

    RootViewController中的其他控件如何控制tabbar controller的切换:

    - (IBAction) clikcOnFirst:(id)sender{

    static int i = 0;

    tabbarController.selectedViewController = [ [tabbarController viewControllers] objectAtIndex: i];

    ++i;

    if ( i > 6 )

    i = 0;

    }

    原文链接:http://www.devdiv.com/iPhone中如何自定义tabbar-weblog-1-1994.html

  • 相关阅读:
    博弈论专题(持续更新)
    数论专题(持续更新)
    树的遍历专题(持续更新)
    直线折线分割平面问题
    字典树模板 HDU1251
    差分数组——面对大数据的处理
    最短路——dijkstra算法
    并查集与最小生成树
    KMP的初步认识及题目分析
    Codeforces Round#636(Div.3) D题 差分数组
  • 原文地址:https://www.cnblogs.com/hopeanCom/p/3047048.html
Copyright © 2011-2022 走看看