我正在根据 for 循环中数组元素的数量将子视图添加到我的滚动视图中。容器视图内部还有一个额外的子视图。问题是只有第一个容器视图包含添加的子视图,而新的容器视图不包含第三个一个也有。我检查了子视图的框架,但似乎仍然不起作用。
CGFloat contentOffset = 0.0f;
//add tej views one by one to scrollview
for (NSString *packageType in packageTypesArray)
{
CGRect lvPackageContainerFrame = CGRectMake(contentOffset, 0.0f,scrollView.frame.size.width,scrollView.frame.size.height);
LVPackageContainer *lvPackageContainer = [[LVPackageContainer alloc] initWithFrame:lvPackageContainerFrame];
NSLog(@"Frame %@",NSStringFromCGRect(lvPackageContainerFrame));
lvPackageContainer.packageType = packageType;
[packageContainersArray addObject:lvPackageContainer];
UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 264, 314)];
NSLog(@"BackgroundImage %@",backgroundImage);
backgroundImage.backgroundColor = [UIColor redColor];
[backgroundImage setImage:[UIImage imageNamed:@"shadowBackground.png"]];
backgroundImage.center = lvPackageContainer.center;
[lvPackageContainer addSubview:backgroundImage];
[scrollView addSubview:lvPackageContainer];
contentOffset += lvPackageContainerFrame.size.width;
scrollView.contentSize = CGSizeMake(contentOffset, scrollView.frame.size.height);
}