I've noticed that, in some fonts, some symbols are displayed incorrectly in UILabel if the frame size for them is determined by NSAttributedString.size or boundingRectWithSize. For example, I chose font AvenirNext-Bold, symbol "A", and set pointSize to 300. Calculated the frame(width = 218.69999999999999, height = 409.80000000000001). I put that character in the frame of the above size.
As you can see in the picture, the parts that cut off of displayed Label are highlighted in the red boxes. I checked several other fonts and noticed that it happens all the time. Can I get rid of this without having to change the frame for the UILabel and correcting margins for symbols in fonts? Using a third-party program, I found out that, for the font AvenirNext-Bold, for the character "A", left and right margins are equal to -1.39.
Does anybody know any techniques to resolve this?
Additional:
If you open Fonts application on your MAC OS, and find Avenir Next Bold font, you can see this cutting off.
Code:
NSString *text = @"A";
NSString *fontName = @"AvenirNext-Bold";
CGFloat pointSize = 300.f;
UIFont *font = [UIFont fontWithName:fontName size:pointSize];
CGSize size = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size;
self.label.text = text;
self.label.font = font;
self.label.frame = CGRectMake((self.view.bounds.size.width - size.width) / 2.f, (self.view.bounds.size.height - size.height) / 2.f, size.width, size.height);
Additional font: You can change font to BodoniSvtyTwoITCTT-BookIta.