我在 for 循环中声明了几个添加到我的 UIScroll 视图中的 UIView,我想知道如何在循环进行时更改每个 UIView 背景的颜色。目前,每个 UIVIew 都保持相同的灰色。
这就是我的代码的样子:
UIScrollView *htmlContainerScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 60.0, self.view.frame.size.width, 293.0)];
NSInteger viewcount = 4;
color = 0;
for(int i = 0; i< viewcount; i++) {
color = color + 4;
NSLog(@"%f", color);
CGFloat y = i * self.view.frame.size.height;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, y,self.view.frame.size.width, self .view.frame.size.height)];
view.backgroundColor = [UIColor colorWithRed:(200.0 + i)/255.0 green:(200.0 + i)/255.0 blue:(200.0 + i)/255.0 alpha:1.0];;
[htmlContainerScrollView addSubview:view];
}