When setting the attribute text UILabel and using setFontSizeToFitWidth, the font size of the attributed text changes as expected. BUT. The text does not vertically align inside the UILabel when the font size of the assigned font changes to a smaller font size.
I need to use the adjustFontSizeToFitWidth method because the attribute string has a variable size. I have a minimum font size of "15.0" and a maximum of "28.0". So I use minimumScaleFactor from "15.0 / 28.0"
My code is:
NSAttributedString *balance = [[NSAttributedString alloc] initWithString:@"12390765298374652938756" attributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.bounds.origin.x + 10, self.bounds.origin.y + 10, self.bounds.size.width - 20, self.bounds.size.height - 20)];
textLabel.attributedText = currencyWithBalance;
textLabel.font = [UIFont fontWithName:@"TitilliumWeb-Light" size:28.0];
textLabel.minimumScaleFactor = 15.0/28.0;
textLabel.textAlignment = NSTextAlignmentCenter;
textLabel.adjustsFontSizeToFitWidth = YES;
textLabel.numberOfLines = 1;
textLabel.backgroundColor = [UIColor redColor];
[self addSubview:textLabel];
Can someone help me achieve this so that the text is also aligned vertically?
Thanks guys.