Skip to content

Commit 14510cf

Browse files
committed
fix: tintColor for iOS 13
1 parent 34a7824 commit 14510cf

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

ios/RCTSegmentedControl.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ - (instancetype)initWithFrame:(CGRect)frame
1818
if ((self = [super initWithFrame:frame])) {
1919
_selectedIndex = self.selectedSegmentIndex;
2020
[self addTarget:self action:@selector(didChange)
21-
forControlEvents:UIControlEventValueChanged];
21+
forControlEvents:UIControlEventValueChanged];
2222
}
2323
return self;
2424
}
@@ -39,6 +39,21 @@ - (void)setSelectedIndex:(NSInteger)selectedIndex
3939
super.selectedSegmentIndex = selectedIndex;
4040
}
4141

42+
- (void)setTintColor:(UIColor *)tintColor
43+
{
44+
[super setTintColor:tintColor];
45+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \
46+
__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
47+
if (@available(iOS 13.0, *)) {
48+
[self setSelectedSegmentTintColor:tintColor];
49+
[self setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}
50+
forState:UIControlStateSelected];
51+
[self setTitleTextAttributes:@{NSForegroundColorAttributeName: tintColor}
52+
forState:UIControlStateNormal];
53+
}
54+
#endif
55+
}
56+
4257
- (void)didChange
4358
{
4459
_selectedIndex = self.selectedSegmentIndex;

0 commit comments

Comments
 (0)