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];
}
我想我的問題是與變量定義的顏色,但我不當然。
所以,要麼下面的答案幫助你的? –