I am new to programming, but I am interested in how to use iosMath
for iOS. I could instal Cocoa Pod already and I did import iosMath
to project. Q
A few problems in your posted code
IBOutlet
then instantiating another MTMathUILabel
with the same namelabel.sizeToFit()
Simple solution is to remove the IBOutlet
, and do as follows
class ViewController: 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.
}
}
Better solution is as follows:
UIView
in storyboard (because MTMathUILabel
is actually a UIView
)MTMathUILabel
IBOutlet
for this viewthen use the following code
class ViewController: UIViewController {
@IBOutlet weak var label: MTMathUILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//NO NEED TO INSTANTIATE A NEW INSTANCE HERE
label.latex = "x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}"
//NO NEED TO CALL sizeToFit()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}