[英]Drawing labels using iosMath library
I'm trying to use iosMath but it shows nothing.我正在尝试使用 iosMath 但它什么也没显示。 How can I use the iosMath library to draw math labels?如何使用 iosMath 库来绘制数学标签?
https://github.com/kostub/iosMath https://github.com/kostub/iosMath
iosMath
is a library for displaying beautifully rendered math equations in iOS and MacOS applications.iosMath
是一个用于在 iOS 和 MacOS 应用程序中显示精美渲染的数学方程的库。 It typesets formulae written using the LaTeX in aUILabel
equivalent class.它在UILabel
等效类中排版使用 LaTeX 编写的公式。 It uses the same typesetting rules as LaTeX and so the equations are rendered exactly as LaTeX would render them.它使用与 LaTeX 相同的排版规则,因此方程的呈现方式与 LaTeX 呈现的方式完全相同。
I installed pod file.我安装了 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.
}
}
I assume this is somewhere in that library's docs, but...我认为这是该图书馆文档中的某个地方,但是......
You need to either give the label
an explicit frame, or call sizeToFit()
:您需要给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
}
}
Result:结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.