iOS入门-26分栏控制器进阶

概述

重点

  • 屏幕底部最多显示5个tab,且最后一个显示为more
  • tab点击之后回调事件
  • 点击more,进入选取页面。可以选取第五个要显示的视图控制器,也可以点击edit进入编辑模式。
  • 编辑过程中各个回调事件

示例

先看图

在这里插入图片描述

示例代码

关于如何配置UIWindow进行适配,参看iOS的UI-04-UIWindow
几个视图控制器类中没做处理,这里就不粘贴出来了。

AppDelegate.h
#import <UIKit/UIKit.h>
//实现UITabBarControllerDelegate代理
@interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate>
//UIWindow属性
@property(retain,nonatomic) UIWindow* window;

@end
AppDelegate.m
#import "AppDelegate.h"
#import "VCFirst.h"
#import "VCSecond.h"
#import "VCThird.h"
#import "VCFourth.h"
#import "VCFifth.h"
#import "VCSixth.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    //初始化六个视图控制器
    VCFirst* vcFirst = [VCFirst new];
    
    VCSecond* vcSecond = [VCSecond new];
    
    VCThird* vcThird = [VCThird new];
    
    VCFourth* vcFourth = [VCFourth new];
    
    VCFifth* vcFifth = [VCFifth new];
    
    VCSixth* vcSixth = [VCSixth new];
    
    //设置title
    vcFirst.title = @"first";
    
    vcSecond.title = @"second";
    
    vcThird.title = @"third";
    
    vcFourth.title = @"fourth";
    
    vcFifth.title = @"fifth";
    
    vcSixth.title = @"sixth";
    
    //设置背景颜色
    vcFirst.view.backgroundColor = [UIColor redColor];
    
    vcSecond.view.backgroundColor = [UIColor greenColor];
    
    vcThird.view.backgroundColor = [UIColor blueColor];
    
    vcFourth.view.backgroundColor = [UIColor orangeColor];
    
    vcFifth.view.backgroundColor = [UIColor purpleColor];
    
    vcSixth.view.backgroundColor = [UIColor brownColor];
    
    //视图控制器添加到数组中
    NSArray* array = [[NSArray alloc] initWithObjects:vcFirst,vcSecond,vcThird,vcFourth,vcFifth,vcSixth, nil];
    //实例化分栏控制器
    UITabBarController* tabC = [[UITabBarController alloc] init];
    //设置代理(后面实现各个方法)
    tabC.delegate = self;
    //给分栏控制器的视图控制器赋值
    tabC.viewControllers = array;
    //设置我们的UIWindow的根控制器
    self.window.rootViewController = tabC;
    //生效并显示
    [self.window makeKeyAndVisible];
    
    return YES;
}

//已经选中
//底部tab选中状态监听
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    NSLog(@"已经选中");
}

//edit点击之后各个回调
//开始编辑前调用
-(void) tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers{
    
    NSLog(@"开始编辑前调用");
}


//结束编辑前调用
-(void) tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers changed:(BOOL)changed{
    NSLog(@"结束编辑前调用");
}

//已经结束调用
-(void) tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers changed:(BOOL)changed{
    NSLog(@"已经结束调用");
}

@end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值