Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // Practice2:Navigation、TabBar
- //
- // Created by Jhen Mu on 2021/7/19.
- //
- import UIKit
- class ViewController: UIViewController {
- //MARK:- Properties
- //MARK:- Methods
- @objc func check(){
- print("check button action")
- }
- @objc func article(){
- self.navigationController?.pushViewController(
- ArticleViewController(), animated: true)
- }
- @objc func setting(){
- self.navigationController?.pushViewController(
- SettingViewController(), animated: true)
- }
- //MARK:- Life Cycle
- override func loadView() {
- super.loadView()
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- theNavigation()
- theTabBar()
- }
- //MARK:-setNavigationBar
- func theNavigation(){
- self.view.backgroundColor = UIColor.white
- self.title = "HomePage"
- self.navigationController?.navigationBar.barTintColor = UIColor.white //設置導覽列的顏色
- self.navigationController?.navigationBar.isTranslucent = false //
- let rightButton = UIBarButtonItem(title: "Setting",
- style: .plain,
- target: self,
- action: #selector(ViewController.setting))
- let leftButton = UIBarButtonItem(title: "Article",
- style: .plain,
- target: self,
- action: #selector(ViewController.article))
- self.navigationItem.rightBarButtonItem = rightButton
- self.navigationItem.leftBarButtonItem = leftButton
- }
- //MARK:-setTabBar
- func theTabBar(){
- self.tabBarController?.tabBar.barTintColor = UIColor.white
- self.tabBarController?.tabBar.isTranslucent = false
- let theTabBar = UITabBarController()
- theTabBar.tabBar.backgroundColor = UIColor.white
- let mainpage = ViewController()
- let article = ArticleViewController()
- let settings = SettingViewController()
- let intro = IntroViewController()
- article.tabBarItem = UITabBarItem(title: "Article",
- image:UIImage(named:"paid-articles"),
- tag: 200)
- settings.tabBarItem = UITabBarItem(title: "Setting",
- image:UIImage(named:"settings"),
- tag: 200)
- intro.tabBarItem = UITabBarItem(title: "Introdce",
- image:UIImage(named:"light-bulb"),
- tag: 200)
- theTabBar.viewControllers = [
- mainpage,article,settings,intro
- ]
- theTabBar.selectedIndex = 2
- }
- //在viewDidLoad之後被執行,時間點在view被呈現之前,每次切換頁面時都會被執行
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- print("viewWillAppear")
- }
- //時間點在viewWillAppear呈現之後被執行,時間在View呈現後,每次切換到這個頁面都會被執行
- override func viewDidAppear(_ animated: Bool) {
- print("viewDidAppear")
- }
- //執行的時間點在 View 要結束前,每次要切換到別頁或是退出這個頁面時都會執行。
- override func viewWillDisappear(_ animated: Bool) {
- super.viewWillDisappear(animated)
- print("viewWillDisappear")
- }
- //執行的時間點在 View 完全結束後,每次要切換到別頁或是退出這個頁面時都會執行。
- override func viewDidDisappear(_ animated: Bool) {
- print("viewDidDisappear")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement