From be89e4d928a504de304f5afb19bd3cc15ae3eb7d Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Tue, 15 Oct 2019 08:10:34 -0700 Subject: [PATCH] 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 --- React/Views/RCTSegmentedControl.m | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/React/Views/RCTSegmentedControl.m b/React/Views/RCTSegmentedControl.m index adbde608e23..343643150a6 100644 --- a/React/Views/RCTSegmentedControl.m +++ b/React/Views/RCTSegmentedControl.m @@ -39,6 +39,21 @@ super.selectedSegmentIndex = selectedIndex; } +- (void)setTintColor:(UIColor *)tintColor +{ + [super setTintColor:tintColor]; +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \ + __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 + if (@available(iOS 13.0, *)) { + [self setSelectedSegmentTintColor:tintColor]; + [self setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]} + forState:UIControlStateSelected]; + [self setTitleTextAttributes:@{NSForegroundColorAttributeName: tintColor} + forState:UIControlStateNormal]; + } +#endif +} + - (void)didChange { _selectedIndex = self.selectedSegmentIndex;