iosMath
iosMath copied to clipboard
SizeToFit sometimes sizes the Label too small
So I am using your Label (awesome work btw) in my App and I need the label to be exactly the size of its content. So overtime the latex is changed i apply sizeToFit() this works fine in long statements but in shorter ones (for example just x) some of the content is cut. How do I fix it ?
Thanks a lot for your help and contribution to this awesome project !
All my best, Jony
Can you provide an example where the sizeToFit returns an incorrect size? It is supposed to be exact.
@kostub I had the same issue. I modified sizeThatFits method in MTMathLabel.m into something like this:
if (calculatedWidth >= size.width) {
size.width = calculatedWidth;
}
if (calculatedHeight >= size.height) {
size.height = calculatedHeight;
}
Quick but dirty fix.
So this is the code I am using:
let label = MTMathUILabel()
label.frame = CGRect(x: 15, y: 60, width: 1, height: 1)
label.latex = "x"
label.sizeToFit()
label.textColor = UIColor.red
label.backgroundColor = UIColor.blue
self.view.addSubview(label)
I changed the colours to make this clearer.
And this is what I am getting.
MTMathUILabel.m file.
adding 4-3 pixels to
size.width
and size.height
will solve the problem.