美文网首页
iOS-系统版UITabbarController和Naviga

iOS-系统版UITabbarController和Naviga

作者: Mn_Su | 来源:发表于2016-09-23 13:32 被阅读0次

    效果图如下:


    16E992D0-FDF8-4E2A-A08A-1BE54655F63A.png

    一.创建一个UITabbarController,并在AppDelegate中的 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法设置

        self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
        //tabbar控制器
        ShopPageBarController *tab = [[ShopPageBarController alloc] init];
        self.window.rootViewController = tab;
        self.window.backgroundColor = WHITECOLOR;
        [self.window makeKeyAndVisible];
    

    二.在 ShopPageBarController.m 文件中实现封装方法

        - (void)viewDidLoad{
            [super viewDidLoad];
            [self createSystemTabbar];
        }
        
        //自封装方法
        -(UINavigationController*)createNavWithViewController:(UIViewController *)viewController WithTitle:(NSString*) title image:(UIImage*)image
        {
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewController];
            viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image tag:0];
            viewController.title = title;
            return nav;
        }
        
        //创建系统tabbar
        - (void)createSystemTabbar{
            HomePagController *page = [[HomePagController alloc] init];
            CategoryController *cate = [[CategoryController alloc] init];
            UIViewController *vc = [[UIViewController alloc] init];
            UIViewController *vc1 = [[UIViewController alloc] init];
            UIViewController *vc2 = [[UIViewController alloc] init];
        
        //数组设置
            self.viewControllers = [NSArray arrayWithObjects:[self createNavWithViewController:page WithTitle:@"首页"  image:[UIImage imageNamed:@"icon-d-4"]],
                                    [self createNavWithViewController:cate WithTitle:@"分类" image:[UIImage imageNamed:@"icond-3"]],
                                    [self createNavWithViewController:vc WithTitle:nil image:nil],
                                    [self createNavWithViewController:vc1 WithTitle:@"实时定位" image:[UIImage imageNamed:@"icon-d-1"]],
                                    [self createNavWithViewController:vc2 WithTitle:@"我的" image:[UIImage imageNamed:@"icon-d-2"]],
                                    nil];
        
            
            //中间突出按钮设置
            UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0.0,0.0,65,65)];
            button.center = CGPointMake(WIDTH/2,15);
            [button setBackgroundImage:[UIImage imageNamed:@"icon-z"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(pickClick) forControlEvents:UIControlEventTouchUpInside];
            [self.tabBar addSubview:button];
        
            
        }
        
        //点击事件
        - (void)pickClick{
            
        }
    

    相关文章

      网友评论

          本文标题:iOS-系统版UITabbarController和Naviga

          本文链接:https://www.haomeiwen.com/subject/gwutyttx.html