在下面的实现中,图像是从数据库中获取的,一旦我放置一个调试点并查看webservice返回的图像数量,它就会显示五个。但是,在我的滚动视图中,只显示三个图像。
-(void) setSizeSliding
{
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
NSString*slidingImage = [[colors objectAtIndex:i] valueForKey:@"picture"];
NSURL *url = [NSURL URLWithString:slidingImage];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
UIImage *tmpImage = [[UIImage alloc] initWithData:data];
UIImageView *slidingImageView = [[UIImageView alloc]initWithFrame:frame];
slidingImageView.image = tmpImage;
[self.scrollView addSubview:slidingImageView];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);
}
更新
如果我更改页面控制页面属性,那么我可以向上滚动到所有五个图像。但是,我怎么能避免使用const值?
答案 0 :(得分:0)
以下是解决方案,一旦我将self.pageControl.numberOfPages
添加到我的代码中,就可以了。
-(void) setSizeSliding
{
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
NSString*slidingImage = [[colors objectAtIndex:i] valueForKey:@"picture"];
NSURL *url = [NSURL URLWithString:slidingImage];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
UIImage *tmpImage = [[UIImage alloc] initWithData:data];
UIImageView *slidingImageView = [[UIImageView alloc]initWithFrame:frame];
slidingImageView.image = tmpImage;
[self.scrollView addSubview:slidingImageView];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);
//solution
// the following code needs to be added to handle number of pages
self.pageControl.numberOfPages = colors.count;
}