@@ -59,6 +59,7 @@ - (instancetype)initWithText:(NSString *)text
5959 if (self = [super initWithFrame: (CGRect){0 ,0 , 288 .0f , 50 .0f }]) {
6060 [self roundedButtonCommonInit ];
6161 _titleLabel.text = text;
62+ [_titleLabel sizeToFit ];
6263 }
6364
6465 return self;
@@ -113,8 +114,7 @@ - (void)roundedButtonCommonInit
113114 [self .containerView addSubview: self .backgroundView];
114115
115116 // Create the title label that will display the button text
116- UIFont *buttonFont = [UIFont preferredFontForTextStyle: UIFontTextStyleBody];
117- buttonFont = [UIFont systemFontOfSize: buttonFont.pointSize weight: UIFontWeightBold];
117+ UIFont *buttonFont = [UIFont systemFontOfSize: 17 .0f weight: UIFontWeightBold];
118118 if (@available (iOS 11.0 , *)) {
119119 // Apply resizable button metrics to font
120120 UIFontMetrics *metrics = [[UIFontMetrics alloc ] initForTextStyle: UIFontTextStyleBody];
@@ -128,7 +128,6 @@ - (void)roundedButtonCommonInit
128128 self.titleLabel .adjustsFontForContentSizeCategory = YES ;
129129 self.titleLabel .backgroundColor = self.tintColor ;
130130 self.titleLabel .text = @" Button" ;
131- [self .titleLabel sizeToFit ];
132131 [self .containerView addSubview: self .titleLabel];
133132
134133 // Create action events for all possible interactions with this control
@@ -145,6 +144,7 @@ - (void)layoutSubviews
145144 [super layoutSubviews ];
146145
147146 // Configure the button text
147+ [self .titleLabel sizeToFit ];
148148 self.titleLabel .center = self.containerView .center ;
149149 self.titleLabel .frame = CGRectIntegral (self.titleLabel .frame );
150150}
0 commit comments