我有一个UIScrollView
我想用一个UIPageControl
来让不同的页面水平滑动。我需要为每一页添加一个UITextView
和一个数字。UIImageView
在我的ViewController
我调用一个网络服务,当数据到达时,我添加如下项目:
for(int i=0;i<[arrData count];i++) {
NSString *body=@"Dummy text";
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size.width = self.scrollView.frame.size.width;
frame.size.height = 40; //vedere landscape
UILabel *label = [[UILabel alloc] initWithFrame:frame];
[label setText:body];
label.numberOfLines=0;
[label sizeToFit];
label.autoresizingMask=UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.scrollView addSubview:label];
[label setBackgroundColor:[UIColor whiteColor]];
[self.scrollView addSubview:label];
int y_pos=label.frame.size.height+10;
int x_pos=0;
for(int img=0; img<[[[arrData objectAtIndex:i]objectForKey:@"images"] count]; img++) {
NSString *imageURL=[[[[arrData objectAtIndex:i] objectForKey:@"images"] objectAtIndex:img] objectForKey:@"fn"];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageURL]];
UIImage *image = [UIImage imageWithData:imageData];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[imageView setFrame:CGRectMake(self.scrollView.frame.size.width * i+img*100, y_pos, image.size.width, image.size.height)];
[self.scrollView addSubview:imageView];
}
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * [arrData count], self.scrollView.frame.size.height);
ScrollView
它在纵向上运行良好,但是当设备旋转时,显然布局被破坏了......这是使用with的最佳方式PageControl
?我是否必须处理旋转并更改插入项目之间的距离,或者(我认为)是否有更好的方法来构建所有内容?