Je veux changer la couleur de fond de ma fenêtre chaque seconde alors voici mon code:changer la couleur de fond de la fenêtre
- (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];
}
Je pense que mon problème est dans la définition des couleurs avec les variables, mais je ne suis pas sûr.
Ainsi, ont l'une des réponses ci-dessous vous a aidé? –