UISB 分栏控制器

scenedelegate.m

 

#import "SceneDelegate.h"
#import "VCFirst.h"
#import "VCSecond.h"
#import "VCThird.h"
@interface SceneDelegate ()

@end

@implementation SceneDelegate


- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
    self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene];
    self.window.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    
    [self.window makeKeyAndVisible];
    
    VCFirst* vcFirst=[[VCFirst alloc]init];
    vcFirst.view.backgroundColor=[UIColor blueColor];
    
    
    VCSecond* vcSecond=[[VCSecond alloc]init];
    vcSecond.view.backgroundColor=[UIColor redColor];
    
    VCThird* vcThird=[[VCThird alloc]init];
    
    
    vcFirst.title=@"视图一";
    vcSecond.title=@"视图二";
    vcThird.title=@"视图三";
    vcThird.view.backgroundColor=[UIColor yellowColor];

    
//    创建试图控制器
    UITabBarController* tbController=[[UITabBarController alloc]init];
//    创建视图控制器数组
//    将所有分栏控制器加到数组中
    NSArray* arrayVC=[NSArray arrayWithObjects:vcFirst,vcSecond,vcThird, nil];
//    将分栏控制器管理数组赋值
    tbController.viewControllers=arrayVC;
//    将分栏控制器为根视图控制器
    self.window.rootViewController=tbController;
//    设置选中视图控制器的索引
    tbController.selectedIndex=2;
    
    
    if(tbController.selectedViewController==vcThird){
        NSLog(@"当前显示的视图控制器三");
        
    }
//    设置透明度
    tbController.tabBar.translucent=NO;
    
    
}

 

 

VCSecond.m

 

//

#import "VCSecond.h"

@interface VCSecond ()

@end

@implementation VCSecond

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UITabBarItem* tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:101];
    
    
    self.tabBarItem=tabBarItem;
    
    
    
}

 

 

VCThird.m

#import "VCThird.h"

@interface VCThird ()

@end

@implementation VCThird

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIBarButtonItem* taBarItem=[[UITabBarItem alloc]initWithTitle:@"111" image:nil tag:101];
    
    self.tabBarItem=taBarItem;
    
}

 

posted @ 2020-09-28 22:31  逆欢  阅读(132)  评论(0编辑  收藏  举报