美文网首页
IOS开发 分栏控制器高级

IOS开发 分栏控制器高级

作者: 奔跑的小小鱼 | 来源:发表于2017-05-27 21:47 被阅读33次

本节学习内容:

1.分栏控件器的代理使用

2.分校控制器的协义方法

3.分栏控制器的高级使用

分栏控制器高级协义函数

willBeginCustomizingViewcontrollers:即将显示编辑方法

willEndCustomizingViewControllers:妈将结束编辑方法

didEndCustonmizingViewControllers:已经结束编辑方法

didSelectViewController:选中控制器切换方法


创建6个视图控器,分别为VCFirst,VCSecond,VCThird,VCFour,VCFive,VCSix都继承于UIViewController

【AppDelegate.h】

#import<UIKit/UIKit.h>

@interface

//添加UITabBarController代理  UITabBarControllerDelegate

AppDelegate:UIResponder<UIApplicationDelegate,UITabBarControllerDelegate>

@property(strong,nonatomic)UIWindow *window;

@end

【AppDelegate.m】

#import "AppDelegate.h"

#import"VCFirst.h"

#import"VCSecond.h"

#import"VCThird.h"

#import"VCFour.h"

#import"VCFive.h"

#import"VCSix.h"

@interface AppDelegate()

@end

@implementation AppDelegate

-(BOOL)application:(UIApplication *)application didFinshLaunchingWithOptions:(NSDictionary *)launchOptions{

self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

[self.window makeKeyAndVisible];

VCFirst* vc01=[[VCFirst alloc]init];

VCSecond* vc02=[[VCSecond alloc]init];

VCThird* vc03=[[VCThird alloc]init];

VCFour* vc04=[[VCFour alloc]init];

VCSix* vc06=[[VCSix alloc]init];

vc01.view.backgroundColor=[UIColor blueColor];

vc02.view.backgroundColor=[UIColor YellowColor];

vc03.view.backgroundColor=[UIColor purpleColor];

vc04.view.backgroundColor=[UIColor grayColor];

vc05.view.backgroundColor=[UIColor greenColor];

vc06.view.backgroundColor=[UIColor orangeColor];

vc01.title="视图1";

vc02.title="视图2";

vc03.title="视图3";

vc04.title="视图4";

vc05.title="视图5";

vc06.title="视图6";

//创建数据

NSArray* arrayVC=[NSArray arrayWithObjects:VC01,vc02,vc03,vc04,vc05,vc06,nil];

UITabBarController* tbc=[[UITabBarController alloc]init];

tbc.viewController=arrayVC;

tbc.tabBar.translucent=NO;

self.window.rootViewController=tbc;

//改变工具栏颜色

tbc.tabBar.barTintColor=[UIColor redColor];

//更改按钮风格颜色

tbc.tabBar.tintColor=[UIColor blackColor];

//添加代理

tbc.delegate=self;

return YES;

}

//开始编辑前调用

-(void)tabBarController:(UITabBarController *)tabBarController willBeginCustonizingViewControllers:(NSArray<_kindof UIViewController *> *)viewControllers{

NSLog(@"编辑器前");

}

-(void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray<_kindof UIViewController *>*)viewControllers changed:(BOOL)changed{

NSLog("即将结束前");

}

-(void)tabBarController:(UITabBarController *)tabBarController didEndCustonizingViewContollers:(NSArray<_kindof UIViewController *>>*)viewControllers changed:(BOOL)changed{

NSLog(@"VCS=%@,viewControllers");

if(changed==YES){

NSLog(@"顺序发生改变!");

}

NSLog(@"已经结束编辑!");

}

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{

//选中的制器的索引与传入的索引是否一样

if(tabBarController.viewControllers[tabBarController.selectedInded]==viewController){

NSLog(@"OK");

}

NSLog(@"选 中控制器对象");

}

相关文章

网友评论

      本文标题:IOS开发 分栏控制器高级

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