iosMath icon indicating copy to clipboard operation
iosMath copied to clipboard

SizeToFit sometimes sizes the Label too small

Open MFJones21 opened this issue 7 years ago • 4 comments

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

MFJones21 avatar Apr 17 '17 12:04 MFJones21

Can you provide an example where the sizeToFit returns an incorrect size? It is supposed to be exact.

kostub avatar May 08 '17 06:05 kostub

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

AnZhg avatar May 09 '17 20:05 AnZhg

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. bildschirmfoto 2017-05-14 um 19 17 34

MFJones21 avatar May 14 '17 17:05 MFJones21

2017-08-25 22 51 32 MTMathUILabel.m file. adding 4-3 pixels to size.width and size.height will solve the problem.

sergey1w avatar Aug 25 '17 19:08 sergey1w