• iOS设计之 多视图导航栏UINavigationController切换视图的简单设计


    在iOS平台上创建有个工程,之后在工程中创建两个类视图
    操作步骤如下
    1、在分别在两个类视图中对主视图设置背景色
     
    FirstViewController.m

    #import "FirstViewController.h"

    @interface FirstViewController ()

    @end

    @implementation FirstViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
       
        //设置主视图的背景色
        self.view.backgroundColor=[UIColor greenColor];
     
       
    }
     
     SecondViewController.m

    #import "SecondViewController.h"

    @interface SecondViewController ()

    @end

    @implementation SecondViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
      //设置主视图的背景色
        self.view.backgroundColor=[UIColor blueColor];
     
    }
     
     
     
    2、在 AppDelegate中创建导航栏和根视图
    AppDelegate.h
     

    #import <UIKit/UIKit.h>
    #import "FirstViewController.h"
    #import "SecondViewController.h"
    @interface AppDelegate : UIResponder <UIApplicationDelegate>

    @property (strong, nonatomic) UIWindow *window;

    @end
     
     
     AppDelegate.m

    #import "AppDelegate.h"

    @interface AppDelegate ()

    @end

    @implementation AppDelegate


    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
       
        //创建视图对象
        FirstViewController *firstVC=[[FirstViewController alloc]init];
        SecondViewController *secondVC=[[SecondViewController alloc]init];
        //导航栏
        UINavigationController *naviGC=[[UINavigationController alloc]initWithRootViewController:firstVC];
        naviGC.tabBarItem.title=@"first";
        naviGC.tabBarItem.badgeValue=@"4";
       
        secondVC.tabBarItem.title=@"second";
        secondVC.tabBarItem.badgeValue=@"1";
       
        UITabBarController *tabBarC=[[UITabBarController alloc]init];
        [tabBarC setViewControllers:@[naviGC,secondVC]];
       
        //根视图
        self.window.rootViewController=tabBarC;
       
       
        return YES;
    }
     
    3、结果效果图
    分别点击视图的中的“4(first)”和“1(second)”可以切换到对应的视图
  • 相关阅读:
    exec系列函数和system函数
    fork函数相关总结
    文件的内核结构file和dup实现重定向
    进程基本概述
    fcntl 函数与文件锁
    文件的属性
    目录的操作
    文件的读取写入
    文件的打开关闭
    浅谈原始套接字 SOCK_RAW 的内幕及其应用(port scan, packet sniffer, syn flood, icmp flood)
  • 原文地址:https://www.cnblogs.com/guiyangxueyuan/p/5277119.html
Copyright © 2020-2023  润新知