MathEditor
MathEditor copied to clipboard
Implement UILabel-like autoshrinking
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:
- Use binary search or similar approach to find an optimal size over a few iterations.
- 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.
- (not the clearest one, but robust) Just resize the rendered image to fit label.
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.