SwiftUI reuse old items UIViewcontroller of Code (2020 edition Tutorial)

SwiftUI reuse old items UIViewcontroller of Code (2020 edition Tutorial)

SwiftUI very easy to use, fast and efficient interface to develop, but specific to the operational level, with a history of code reuse is necessary to study the matter.

How to call in UIViewcontroller in SwiftUI

  • 1. Create a Wrapper
    For example, we have a Example1ViewController old code, we can start by creating a UIViewControllerRepresentable Wrapper
import Foundation
import SwiftUI

struct MKControllerWrapper: UIViewControllerRepresentable {
    typealias UIViewControllerType = Example1ViewController

    func makeUIViewController(context: UIViewControllerRepresentableContext<MKControllerWrapper>) -> MKControllerWrapper.UIViewControllerType {

  
      return Example1ViewController()

    }

    func updateUIViewController(_ uiViewController: MKControllerWrapper.UIViewControllerType, context: UIViewControllerRepresentableContext<MKControllerWrapper>) {
        //
    }
}
  • 2, you can call the Wrapper code in SwiftUI
 NavigationLink( destination: MKControllerWrapper()){
                    Text("  Markdown文本编辑器  ")
                        .bold()
                        .foregroundColor(.white)
                        .background(Color.purple)
                        .cornerRadius(6)
                        .shadow(radius: 4)
                }

effect

41,085-bf223bcba1b5274e.png
SwiftUI reuse old items SwiftUI interface
41085-94afe51f4b67a114.png
SwiftUI reuse old history of the project code interface

More attention SwiftUI tutorials and code columns

Published 637 original articles · won praise 4 · views 50000 +

Guess you like

Origin blog.csdn.net/iCloudEnd/article/details/104059673