How to change UIWindow color from a separate class?

I am trying to change the background color of a UIWindow when an action is submitted to the MyController class. However, UIWindow is in the AppDelegate class, so I don't have access to the variable to change it using

window.backgroundColor = [UIColor theColor];

in MyController. Here is the code for MyController.m:

@implementation MyController
- (IBAction) sliderChanged: (id) sender {
 // want to call some method to change the UIWindow background color
}
@end

And here is the code for AppDelegate.h:

@interface AppDelegate: NSObject {
    UIWindow * window;
}

- (void) changeColorToRed: (int) r Green: (int) g Blue: (int) b;

@property (nonatomic, retain) IBOutlet UIWindow * window;

@end

changeColorToRed... AppDelegate, window, sliderChanged MyController.

UIWindow * ?

+3
2
[UIApplication sharedApplication].delegate.window.backgroundColor = [UIColor myColor];

1 ,

[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor myColor];
+9

, :

,

.

0

Source: https://habr.com/ru/post/1727883/


All Articles