美文网首页
iOS开发笔记之MYWebViewController_基于WK

iOS开发笔记之MYWebViewController_基于WK

作者: iOS_朱益锋 | 来源:发表于2017-07-21 10:18 被阅读87次
    准备好所有UI控件
    • webView
    lazy var webView: WKWebView = {
            let config = WKWebViewConfiguration()
            config.userContentController = WKUserContentController()
            let view = WKWebView(frame: CGRect.zero, configuration: config)
            view.uiDelegate = self
            view.navigationDelegate = self
            return view
        }()
    
    • progressView
    lazy var progressView: UIProgressView = {
            let progressView = UIProgressView()
            progressView.progressTintColor = .green
            progressView.progressViewStyle = .bar
            progressView.progress = 0.0
            return progressView
        }()
    
    • closeButton
    lazy var closeButton: UIBarButtonItem = {
            let button = UIBarButtonItem(title: "关闭", style: UIBarButtonItemStyle.plain, target: self, action: #selector(MYWebViewController.closeAction(_:)))
            return button
        }()
    
    • goBackButton
     lazy var goBackButton: UIBarButtonItem = {
            let button = UIBarButtonItem(title: "返回", style: UIBarButtonItemStyle.plain, target: self, action: #selector(MYWebViewController.goBackAction(_:)))
            return button
        }()
    
    外部URL传入
    public var url: URL?
    
    控制progressView
    fileprivate var progress: Float {
            get {
                return self.progressView.progress
            }
            set {
                if newValue >= 1.0 {
                    self.progressView.alpha = 0.0
                }else {
                    self.progressView.alpha = 1.0
                }
            }
        }
    
    控制closeButton
     fileprivate var showClosedButton = true {
            didSet {
                guard self.isViewLoaded else {
                    return
                }
                if self.showClosedButton {
                    self.navigationItem.leftBarButtonItems = [self.goBackButton, self.closeButton]
                }else {
                    self.navigationItem.leftBarButtonItems = [self.goBackButton]
                }
            }
        }
    

    相关文章

      网友评论

          本文标题:iOS开发笔记之MYWebViewController_基于WK

          本文链接:https://www.haomeiwen.com/subject/zhhhottx.html