繁体   English   中英

使用 iosMath 库绘制标签

[英]Drawing labels using iosMath library

我正在尝试使用 iosMath 但它什么也没显示。 如何使用 iosMath 库来绘制数学标签?

https://github.com/kostub/iosMath

iosMath是一个用于在 iOS 和 MacOS 应用程序中显示精美渲染的数学方程的库。 它在UILabel等效类中排版使用 LaTeX 编写的公式。 它使用与 LaTeX 相同的排版规则,因此方程的呈现方式与 LaTeX 呈现的方式完全相同。

我安装了 pod 文件。

import UIKit
import Foundation
import CoreGraphics
import QuartzCore
import CoreText
import iosMath


class Deneme_VC: UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let label: MTMathUILabel = MTMathUILabel()
        label.latex = "x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}"

        //ADD THIS LABE TO THE VIEW HEIRARCHY
        view.addSubview(label)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

在此处输入图片说明

我认为这是该图书馆文档中的某个地方,但是......

您需要给label一个明确的框架,或者调用sizeToFit()

import UIKit

import CoreGraphics
import QuartzCore
import CoreText
import iosMath

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let label: MTMathUILabel = MTMathUILabel()
        label.latex = "x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}"
        
        //ADD THIS LABE TO THE VIEW HEIRARCHY
        view.addSubview(label)
        
        // need to call sizeToFit() to get it to calculate the frame
        label.sizeToFit()
        
        // center it in the view
        label.center = view.center

        // so we can see the frame
        label.backgroundColor = .yellow
        
    }

}

结果:

在此处输入图片说明

暂无
暂无

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

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