简体   繁体   English

使用 iosMath 和 SwiftUI

[英]using iosMath and SwiftUI

I'm trying to create a small math learning application.我正在尝试创建一个小型数学学习应用程序。

So I installed iosMath, but using SwiftUI I don't know how to declare a MTMathUILabel.所以我安装了 iosMath,但是使用 SwiftUI 我不知道如何声明 MTMathUILabel。

Maybe someone has a lead to help me?也许有人有线索可以帮助我?

I tried this but got the following error message: "Constant'label' inferred to have type '()', which may be unexpected".我试过了,但收到以下错误消息:“Constant'label' 推断为具有类型 '()',这可能是意外的”。


import SwiftUI
import UIKit
import iosMath

struct MyViewMath : View {

    let label = MTMathUILabel().latex="\\sum"

    var body: some View {
        GeometryReader { geo in
            VStack {
                View1()
                Text("\(label)")
                View2()
            }


        }
    }
}

// My view code bellow

Thanks for your help.谢谢你的帮助。

MTMathUILabel is a UIView subclass, so you cannot use it directly in a SwiftUI View . MTMathUILabelUIView子类,因此您不能直接在 SwiftUI View使用它。 Instead, you need to create a new type that conforms to UIViewRepresentable to wrap the MTMathUILabel .相反,您需要创建一个符合UIViewRepresentable的新类型来包装MTMathUILabel Tanu Singhal explains the process in detail in WWDC 2019 Session 231: Integrating SwiftUI . Tanu Singhal 在WWDC 2019 Session 231: Integrating SwiftUI中详细解释了这个过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM