MathEditor icon indicating copy to clipboard operation
MathEditor copied to clipboard

Implement UILabel-like autoshrinking

Open DesmanLead opened this issue 7 years ago • 1 comments

The ideal interface looks like:

@interface MTMathUILabel : UIView
<...>
@property (nonatomic) BOOL adjustsFontSizeToFit;
<...>
@end

Do you have any ideas about the clear way to implement it?

Currently I see the following solutions:

  1. Use binary search or similar approach to find an optimal size over a few iterations.
  2. Calculate ratio of a desired size to an actual size and use it to calculate the font size. This is fast, but in terms of math rendering the font size does not have a constant correlation with an output size.
  3. (not the clearest one, but robust) Just resize the rendered image to fit label.

DesmanLead avatar Mar 30 '17 16:03 DesmanLead

I already have code that does auto-font adjust in the MathEditor example:

https://github.com/kostub/MathEditor/blob/master/MathEditorExample/MTViewController.m#L40

But that only works as you are editing. Doing it for the MathUILabel is a bit more complex and we have to take one of the approaches you've described. Though I'm not sure I understand the approach used by 3.

kostub avatar Mar 30 '17 16:03 kostub