I'm trying to solve this problem as in the application I'm working on I have a lot of fonts, so size of label is being calculated dynamically when user changes font.
The problem that I have is that UILabel is being clipped at the end if font is Italic like on picture bellow:
This is what I have tried so far:
- calculating of width with the help of CoreText and
CGSize CTFramesetterSuggestFrameSizeWithConstraints ( CTFramesetterRef framesetter, CFRange stringRange, CFDictionaryRef frameAttributes, CGSize constraints, CFRange *fitRange );
- calculating of width with the help of NSAttributedString and
- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options context:(NSStringDrawingContext *)context
- calculating of width with the help of NSString and
- (CGSize)sizeWithAttributes:(NSDictionary<NSString *,id> *)attrs
- using temp UITextView and
sizeThatFits´ and
fitToSize`
As there is a lot of fonts in application I need to set width of label dynamically, so subclassing of UILabel and adding few more points on drawFrameInRect
is not working.
Here is sample code on Github.
Any help/advice is appreciated.