我想为我的音乐播放器做一个可视化。所以我画了一个网格视图,我想随机或连续地改变每个正方形的颜色。
我的绘制网格代码
- (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);
}
}
}
看起来像