I have a UIButton and the text is centered within the button normally until the text string gets longer and it starts to scale down the size of the text. Then the text seems to stick to the bottom of the textField instead of staying centered in the button.
self.titleBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
self.titleBtn.titleLabel.minimumScaleFactor = .2;
[self.descriptionBtn setTitle:@"T" forState:UIControlStateNormal];
//works normally
but
[self.descriptionBtn setTitle:@"This a longer title" forState:UIControlStateNormal];
//is vertically lower than center
As noted here :)
You need to user baselineAdjustment
propery of the UILabellabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With