How to change an individual square color in relation to music per beat continuously to create an iPhone visualizer?

I want to make a visualization for my music player. So I draw a grid, and I want to change each square color randomly or continuously.

My code for the drawing grid

- (void)drawRect:(CGRect)rect

 for (int i = 0; i < 4 ;i = i + 1) {
    for (int j = 0; j < 4; j = j + 1) {
        CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetLineWidth(context, 2.0);

CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);

CGRect rectangle = CGRectMake((j*(100+2))+2,(i*(100+2))+2,100,100);

CGContextAddRect(context, rectangle);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
        CGContextFillPath(context);
CGContextStrokePath(context);
    }
}
}

he looks like this image

+4
source share
2 answers

In my opinion, you feel too limited and limit future opportunities. If I were you, I would have a grid of UIViews or UIImageViews placed in an array. (You can do this programmatically or with IB). (You can add edges by changing the border property at the view level)

, , , , , , , , , - , .

, . , " ".

BPM php

+1

, UIView.

setNeedsDisplayInRect: , .

, drawRect: , , !

, ;)

-3

Source: https://habr.com/ru/post/1540342/


All Articles