Skip to content

Commit be89e4d

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Fix tintColor in SegmentedControlIOS component
Summary: iOS 13 introduced a new design for `UISegmentedControl` and new APIs to control this. `[UISegmentedControl tintColor]` is now ignored. We try to maintain backwards compatibility so the appearance is as close as possible to iOS 12. Changelog: Fix `tintColor` on SegmentedControlIOS Reviewed By: shergin Differential Revision: D17905892 fbshipit-source-id: 964ac64c8543660929c43b427dce4f78094b1255
1 parent 8bce9c5 commit be89e4d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

React/Views/RCTSegmentedControl.m

+15
Original file line numberDiff line numberDiff line change
@@ -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)