我想每秒更改一次窗口的背景颜色,所以这是我的代码:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(newColor) userInfo:nil repeats:YES];
}
-(void)newColor {
int r;
r = (arc4random()%250)+1;
NSLog(@"%i", r);
int g;
g = (arc4random()%250)+1;
NSLog(@"%i", g);
int b;
b = (arc4random()%250)+1;
NSLog(@"%i", b);
NSColor *theColor = [NSColor colorWithDeviceRed:(int)r green:(int)g blue:(int)b alpha:(float)1.0];
[_window setBackgroundColor:theColor];
}
我认为我的问题在于用变量定义颜色,但我不确定。