1

How to make UIView background colour continuous changing like an Instagram log-in screen has as shown in the images without load in the memory.

enter image description here enter image description here

Bhargav Kukadiya
  • 418
  • 7
  • 17

1 Answers1

0

To change the background color you just do:

    self.view.backgroundColor=yourColor;

and to change this continuously you can use a timer.IF you have a an array colors for the background, store the colors in an array.

   NSArray *colorArray=@[colo1,color2....colorn];

You can also generate a random color and pass it to the view background.In that case you can just do(In this case, you don't have to store the colors in an array)

      self.view.backgroundColor=metodThatReturnsRandomColor.

OR, declare the timer to call the changeColor method every 1.0 sec .

  @property (nonatomic, retain) NSTimer * timerIvar;


 self.timerIvar  = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(changeColor) userInfo:nil repeats:YES];

and the method would be:

-(void)changeColor{
         if(x<colorArray.count){
        self.view.backgroundColor=colorArray[x];
        }else{
          x=0;
       }
        x++;
  }

The same logic applies for images/ gradient colors.

and remember on viewWillDisappear

- (void)viewWillDisappear:(BOOL)animated
{
  ...
  [self.timerIvar invalidate];
 self.timerIvar = nil;
}
Community
  • 1
  • 1
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
  • Well this will look kind of awful, or you will have to have a really huge array with all color gradations – s1ddok Jul 15 '16 at 12:41
  • It would be better to create a color gradient in the loop instead of picking it up from an array. Otherwise it would look like a cheap neon sign, changing colors. – NSNoob Jul 15 '16 at 12:41
  • I don't think storing colors would create a memory issue as long as you manage it properly. @s1ddok – Teja Nandamuri Jul 15 '16 at 12:43
  • I agrre @NSNoob. Unless the OP has a special requirement of colors, he can create the colors in a loop. If he has a specific set of interests, then storing them in an array would be the simpler solution. – Teja Nandamuri Jul 15 '16 at 12:44