1
我想改变我的窗口背景色每秒钟所以这里是我的代码:改变窗口背景色
- (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];
}
我想我的问题是与变量定义的颜色,但我不当然。
所以,要么下面的答案帮助你的? –