I need to set the font size of the title UILabel of a UIButton programmatically.
This way you can set the fontSize and can handle it in just one class.
extension of UIButton and added following code:- (void)awakeFromNib{
[super awakeFromNib];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.titleLabel setFont:[UIFont fontWithName:@"font"
size:self.titleLabel.font.pointSize]];
[self setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
}
UIButton inside CodeNow if you create a UIButton inside your code, #import the extension of yourUIButton` and create the Button.
Interface BuilderIf you create the UIButton inside the Interface Builder, select the UIButton, go to the Identity Inspector and add the created extension as class for the UIButton.