本文介绍了使用 iosMath 库绘制标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use iosMath but it shows nothing. How can I use the iosMath library to draw math labels?

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.
    }

}

enter image description here

解决方案

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 库绘制标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 21:19