2

I would like to have the background of an app change colour depending on the time, for example if it is 12:34:56 the hex color code would be #123456 so the background would change color to #123456. Is this possible. Also is there any way to could use broader numbers and letters possibly because the format could exclude a lot colours.

Thanks

2 Answers2

0

to set hex color you can refer to: how to set hex color code for background to change it every second - just create specific parser, using `NSDateFormatter:

[dateFormatter setDateFormat:@"hhmmss"]; //hours minutes seconds

and then put it into function and call it every seconds using NSTimer

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(changeBackgroundColor) userInfo:nil repeats:YES]
Community
  • 1
  • 1
Vi Matviichuk
  • 1,122
  • 15
  • 32
0

(Referring the answer from duplicate question suggested)

Try this code:

NSDate *mydate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hhmmss"];
NSString *formattedDateString = [dateFormatter stringFromDate:mydate];

Then I would use

[self.view setBackgroundColor: [self colorWithHexString:formattedDateString ]]; 

Now colorWithHexString method is given in this question link: how to set hex color code for background

Hope this helps you to achieve your requirements.

Community
  • 1
  • 1
Mrunal
  • 13,982
  • 6
  • 52
  • 96