@@ -19,6 +19,7 @@ - (instancetype)initWithFrame:(CGRect)frame
1919 _selectedIndex = self.selectedSegmentIndex ;
2020 [self addTarget: self action: @selector (didChange )
2121 forControlEvents: UIControlEventValueChanged];
22+ _attributes = [[NSMutableDictionary alloc ] init ];
2223 }
2324 return self;
2425}
@@ -38,6 +39,14 @@ - (void)setSelectedIndex:(NSInteger)selectedIndex
3839 super.selectedSegmentIndex = selectedIndex;
3940}
4041
42+ - (void )setFontSize : (NSInteger )fontSize
43+ {
44+ UIFont *font = [UIFont boldSystemFontOfSize: fontSize];
45+ [_attributes setObject: font forKey: NSFontAttributeName ];
46+ [self setTitleTextAttributes: _attributes
47+ forState: UIControlStateNormal];
48+ }
49+
4150- (void )setBackgroundColor : (UIColor *)backgroundColor
4251{
4352 #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
@@ -53,8 +62,9 @@ - (void)setTextColor:(UIColor *)textColor
5362 #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
5463 __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
5564 if (@available (iOS 13.0 , *)) {
56- [self setTitleTextAttributes: @{NSForegroundColorAttributeName : textColor}
57- forState: UIControlStateNormal];
65+ [_attributes setObject: textColor forKey: NSForegroundColorAttributeName ];
66+ [self setTitleTextAttributes: _attributes
67+ forState: UIControlStateNormal];
5868 }
5969 #endif
6070}
0 commit comments