5 自定义访客视图

import UIKit

class LYVisitorVc: UITableViewController {

    var isLogin: Bool = false
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    func setupNavUI() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action:#selector(registerButtonAction))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action:#selector(loginButtonAction))
    }

    
    @objc private func registerButtonAction() {
        
        print("注册")
        
    }
    
    @objc private func loginButtonAction() {

        print("denglu")
        
    }

    
    
    //自定义视图重写 loadView
    override func loadView() {
        
        if isLogin == false {
            
            //没有登录,自定义访客视图
            let visitorV = UIView()
            visitorV.backgroundColor = UIColor.yellow
            view = visitorV
            
            setupNavUI()
            
        } else {
            
            //登录
            super.loadView()
            
        }
    }
    
}

你可能感兴趣的:(5 自定义访客视图)