SwiftUI -- 包装UIKit控件
2021-02-28 本文已影响0人
jancywen
创建一个 struct
遵循 UIViewRepresentable
协议,实现 makeUIView
, updateUIView
方法,将 UIKit 的控件在 makeUIView
方法中返回
import SwiftUI
import UIKit
struct LoadingIndicatorView: UIViewRepresentable {
func makeUIView(context: UIViewRepresentableContext<LoadingIndicatorView>) -> UIView {
let view = UIActivityIndicatorView(style: .medium)
view.startAnimating()
return view
}
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<LoadingIndicatorView>) {
}
}