使用 iosMath 库绘制标签 [英] Drawing labels using iosMath library
本文介绍了使用 iosMath 库绘制标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 iosMath,但它什么也没显示.如何使用 iosMath 库绘制数学标签?
<块引用>I'm trying to use iosMath but it shows nothing. How can I use the iosMath library to draw math labels?
https://github.com/kostub/iosMath
iosMath
is a library for displaying beautifully rendered math equations in iOS and MacOS applications. It typesets formulae written using the LaTeX in aUILabel
equivalent class. It uses the same typesetting rules as LaTeX and so the equations are rendered exactly as LaTeX would render them.
I installed pod file.
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()
:
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:
这篇关于使用 iosMath 库绘制标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文