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

时间:2010-01-09 20:55:12

标签: iphone class background-color uiwindow

当我将一个动作发送到MyController类时,我试图改变UIWindow的背景颜色。然而,UIWindow驻留在AppDelegate类中,因此我无权访问该变量以使用

修改它
window.backgroundColor = [UIColor theColor];
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,但我无法从MyController中的sliderChanged方法调用它。

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

2 个答案:

答案 0 :(得分:12)

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

如果只有一个窗口,

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

答案 1 :(得分:0)

我想你可以:

在包含窗口变量

的类中创建一些静态方法

将窗口变量传递给新类。