`

swift -> NavigationController 创建局部显示/自定义容器 的 NavigationController

 
阅读更多

 

父容器  ViewController.swift

 

import UIKit


class ViewController: UIViewController {
    
    //声明window
    var window: UIWindow?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        self.window = UIWindow(frame: CGRect(x: 10, y: 100, width: 200, height: 300));
        self.window?.layer.masksToBounds  = true;
        self.window?.layer.borderColor  = UIColor.brown.cgColor;
        self.window?.layer.borderWidth  = 5;
        //默认加载的视图
        let nav1 = UINavigationController(rootViewController: Page1(nibName: nil, bundle: nil));
        self.window!.rootViewController = nav1
        self.window?.makeKeyAndVisible()
        //self.window 也可以被其他view.addSubview(self.window) 放入到 指定容器中
        
     
        
    }
    
  
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    
}

 

 

Page1.swift

import UIKit

class Page1: UIViewController {
    
 
    override func viewDidLoad() {
        super.viewDidLoad()
        // 设置导航栏标题
        self.title="One";
        //Item 标题        //Item样式       //目标所有        //nxet 事件触发的方法名字
        let nextItem=UIBarButtonItem(title:"下一页",style:.plain,target:self,action:#selector(Page1.next as (Page1) -> () -> ()));
        //  添加到到导航栏上
        self.navigationItem.rightBarButtonItem = nextItem;
        
        
    }
    
    //Item 事件
    func next()
    {
   
        // 定义一个控制器
        let tow_vc = Page2();
        //推入下一个视图
        self.navigationController?.pushViewController(tow_vc,animated:true);
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    
}

 

page2.swift

import UIKit

class Page2: UIViewController {
 
    override func viewDidLoad() {
        super.viewDidLoad()
        // 设置导航栏标题
        self.title="Tow";
 
        
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
     
    
}

 




 
 

 

 

 

 

  • 大小: 24.9 KB
  • 大小: 28.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics