如何从单独的类更改UIWindow的颜色?

jke*_*esh 5 iphone class background-color uiwindow

我正在尝试在将动作发送到MyController类时更改UIWindow的背景颜色.但是UIWindow驻留在AppDelegate类中,因此我无权访问该变量来使用它来修改它

window.backgroundColor = [UIColor theColor];
Run Code Online (Sandbox Code Playgroud)

在MyController中.这是MyController.m的代码:

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

这是AppDelegate.h的代码:

@interface AppDelegate : NSObject  {
    UIWindow *window;
}

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

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

@end

我试图在AppDelegate类中实现一个方法changeColorToRed ...因为该方法可以访问该变量window,但我无法从sliderChangedMyController中的方法调用它.

如何从其他类修改UIWindow*窗口?

ken*_*ytm 13

[UIApplication sharedApplication].delegate.window.backgroundColor = [UIColor myColor];
Run Code Online (Sandbox Code Playgroud)

如果只有一个窗口,

[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor myColor];
Run Code Online (Sandbox Code Playgroud)