diff --git a/ResearchKit/ActiveTasks/ORKNormalizedReactionTimeContentView.m b/ResearchKit/ActiveTasks/ORKNormalizedReactionTimeContentView.m index 5a3b53ca4..8c6d63a83 100644 --- a/ResearchKit/ActiveTasks/ORKNormalizedReactionTimeContentView.m +++ b/ResearchKit/ActiveTasks/ORKNormalizedReactionTimeContentView.m @@ -78,7 +78,7 @@ - (void)resetAfterDelay:(NSTimeInterval)delay completion:(nullable void (^)(void } -(void)resizeConstraints { - ORKScreenType screenType = ORKGetVerticalScreenTypeForWindow([[[UIApplication sharedApplication] delegate] window]); + ORKScreenType screenType = ORKGetVerticalScreenTypeForWindow([UIApplication sharedApplication].windows.firstObject); if (screenType == ORKScreenTypeiPhone5 ) { NormalizeButtonSize = 70.0; BackgroundViewSpaceMultiplier = 1.75; diff --git a/ResearchKit/ActiveTasks/ORKStroopContentView.m b/ResearchKit/ActiveTasks/ORKStroopContentView.m index 8968578ec..89157b29d 100644 --- a/ResearchKit/ActiveTasks/ORKStroopContentView.m +++ b/ResearchKit/ActiveTasks/ORKStroopContentView.m @@ -61,7 +61,7 @@ - (instancetype)initWithFrame:(CGRect)frame { [_colorLabel setFont:[UIFont systemFontOfSize:60]]; [_colorLabel setAdjustsFontSizeToFitWidth:YES]; - ORKScreenType screenType = ORKGetVerticalScreenTypeForWindow([[[UIApplication sharedApplication] delegate] window]); + ORKScreenType screenType = ORKGetVerticalScreenTypeForWindow([UIApplication sharedApplication].windows.firstObject); if (screenType == ORKScreenTypeiPhone5) { labelWidth = 200.0; @@ -144,7 +144,7 @@ -(void)setupGridButtons { _buttonStackView.axis = UILayoutConstraintAxisVertical; - ORKScreenType screenType = ORKGetVerticalScreenTypeForWindow([[[UIApplication sharedApplication] delegate] window]); + ORKScreenType screenType = ORKGetVerticalScreenTypeForWindow([UIApplication sharedApplication].windows.firstObject); if (screenType == ORKScreenTypeiPhone6) { minimumButtonHeight = 150.0; diff --git a/ResearchKit/Common/ORKHelpers.m b/ResearchKit/Common/ORKHelpers.m index 04bde99d1..9ec8436e6 100644 --- a/ResearchKit/Common/ORKHelpers.m +++ b/ResearchKit/Common/ORKHelpers.m @@ -179,6 +179,36 @@ void ORKAdjustHeightForLabel(UILabel *label) { label.frame = rect; } +#if TARGET_OS_IOS +UIColor *ORKWindowTintColor(UIWindow *window) { + UIColor *windowTintColor = window.tintColor; + if (!windowTintColor) { + return nil; + } + + //Return nil if the window tint color is clear + CGFloat redColor; + CGFloat blueColor; + CGFloat greenColor; + CGFloat alpha; + + [window.tintColor getRed:&redColor green:&greenColor blue:&blueColor alpha:&alpha]; + + if (redColor == 0 && blueColor == 0 && greenColor == 0 && alpha == 0) { + return nil; + } + + return windowTintColor; +} + +UIColor *ORKViewTintColor(UIView *view) { + UIColor *existingTintColor = view.tintColor ? : [UIColor systemBlueColor]; + UIColor *tintColor = ORKWindowTintColor(view.window) ? : existingTintColor; + + return tintColor; +} +#endif + UIImage *ORKImageWithColor(UIColor *color) { CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); diff --git a/ResearchKit/Common/ORKHelpers_Internal.h b/ResearchKit/Common/ORKHelpers_Internal.h index cb63b0c12..98dcf8ed4 100644 --- a/ResearchKit/Common/ORKHelpers_Internal.h +++ b/ResearchKit/Common/ORKHelpers_Internal.h @@ -170,6 +170,11 @@ ORK_EXTERN NSString *ORKFileProtectionFromMode(ORKFileProtectionMode mode); CGFloat ORKExpectedLabelHeight(UILabel *label); void ORKAdjustHeightForLabel(UILabel *label); +#if TARGET_OS_IOS +UIColor * _Nullable ORKWindowTintColor(UIWindow *window); +UIColor * ORKViewTintColor(UIView *view); +#endif + // build a image with color UIImage *ORKImageWithColor(UIColor *color); diff --git a/ResearchKit/Common/ORKNavigationContainerView.m b/ResearchKit/Common/ORKNavigationContainerView.m index 980a7e4ce..19d461814 100644 --- a/ResearchKit/Common/ORKNavigationContainerView.m +++ b/ResearchKit/Common/ORKNavigationContainerView.m @@ -267,6 +267,14 @@ - (void)setupViews { [self arrangeSubStacks]; } +- (void)didMoveToWindow { + _appTintColor = ORKViewTintColor(self); + + _cancelButton.normalTintColor = _appTintColor; + _continueButton.normalTintColor = _appTintColor; + _skipButton.normalTintColor = _appTintColor; +} + - (void)setupGrandparentStackView { if (!_grandparentStackView) { _grandparentStackView = [[UIStackView alloc] init]; @@ -351,7 +359,6 @@ - (void)setupSubStackViews { [_parentStackView addArrangedSubview:subStack]; } } - _appTintColor = [[UIApplication sharedApplication].delegate window].tintColor; [self setupContinueButton]; [self setupCancelButton]; [self setupSkipButton]; diff --git a/ResearchKit/Common/ORKOrderedTask+ORKPredefinedActiveTask.m b/ResearchKit/Common/ORKOrderedTask+ORKPredefinedActiveTask.m index be6608f52..27654f9e6 100644 --- a/ResearchKit/Common/ORKOrderedTask+ORKPredefinedActiveTask.m +++ b/ResearchKit/Common/ORKOrderedTask+ORKPredefinedActiveTask.m @@ -178,7 +178,7 @@ + (ORKOrderedTask *)amslerGridTaskWithIdentifier:(NSString *)identifier intendedUseDescription:(NSString *)intendedUseDescription options:(ORKPredefinedTaskOption)options { NSMutableArray *steps = [NSMutableArray array]; - UIColor *tintColor = [[[UIApplication sharedApplication] delegate] window].tintColor ? : ORKColor(ORKBlueHighlightColorKey); + UIColor *tintColor = [UIApplication sharedApplication].windows.firstObject.tintColor ? : ORKColor(ORKBlueHighlightColorKey); if (!(options & ORKPredefinedTaskOptionExcludeInstructions)) { {