我在滚动视图中创建了一个标签。for循环计数超过1000。当时滚动很慢。如果数据量较少(200、300,...),则其滚动顺畅。我正在使用以下代码创建标签。
UILabel *modelLabel;
UIButton *modelButton;
for (int i = 0; i < [modelArray count]; i++)
{
modelButton = [UIButton buttonWithType:UIButtonTypeCustom];
modelButton.frame = CGRectMake(0.0, (i * LABEL_HEIGHT), LABEL_WIDTH, LABEL_HEIGHT);
modelButton.tag = i+100;
[modelButton addTarget:nil action:@selector(modelButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[modelScrollView addSubview:modelButton];
modelLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, (i * LABEL_HEIGHT), LABEL_WIDTH, LABEL_HEIGHT)];
modelLabel.text = [NSString stringWithFormat:@"%@", [[modelArray objectAtIndex:i] valueForKey:@"Model"]];
modelLabel.tag = i+1000;
modelLabel.backgroundColor = [UIColor clearColor];
modelLabel.textColor = [UIColor grayColor];
modelLabel.alpha = 0.5;
modelLabel.textAlignment = UITextAlignmentCenter;
modelLabel.font = EUROSLITE_FONT(14);
[modelScrollView addSubview:modelLabel];
}
[modelScrollView setContentSize:CGSizeMake(280.0, ([modelArray count] * LABEL_HEIGHT))];
我该如何解决这个问题?
提前致谢。