我在我的项目中使用了slider from this。将图像数组加载到IOS中的滑块中
在此滑块中,它们使用静态图像传递给滑块,并且这些图像在滑块中可见。但我有来自服务的图像数组,我将这个数组传递给滑块,滑块工作正常,但它不显示滑块中的图像。我很困惑,为什么它不显示它。我对滑块代码,
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSArray *arrayOfImages = [userDefaults objectForKey:@"property_images"];
NSLog(@"GGG %@",arrayOfImages);
//self.imagesData=[[NSArray alloc]init];
self.imagesData = arrayOfImages; //[_Image1 mutableCopy]; //@[@"image1.jpg", @"image2.jpg", @"image3.jpg"];
NSLog(@"Image Array is %@",_imagesData);
for(int i=0; i<self.imagesData.count;i++){
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.frame) * i, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.scrollView.frame))];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.image = [UIImage imageNamed:[self.imagesData objectAtIndex:i]];
[self.scrollView addSubview:imageView];
}
self.scrollView.delegate = self;
index=0;
// Progammatically init a TAPageControl with a custom dot view.
self.customPageControl2 = [[TAPageControl alloc] initWithFrame:CGRectMake(20,self.scrollView.frame.origin.y+self.scrollView.frame.size.height,self.scrollView.frame.size.width,40)];//CGRectMake(0, CGRectGetMaxY(self.scrollView.frame) - 100, CGRectGetWidth(self.scrollView.frame), 40)
// Example for touch bullet event
self.customPageControl2.delegate = self;
self.customPageControl2.numberOfPages = self.imagesData.count;
self.customPageControl2.dotSize = CGSizeMake(20, 20);
self.scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.view.frame) * self.imagesData.count, CGRectGetHeight(self.scrollView.frame));
[self.view addSubview:self.customPageControl2];
和滑块的进一步功能是这个,
-(void)viewDidAppear:(BOOL)animated{
timer=[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(runImages) userInfo:nil repeats:YES];
}
-(void)viewDidDisappear:(BOOL)animated{
if (timer) {
[timer invalidate];
timer=nil;
}
}
-(void)runImages{
self.customPageControl2.currentPage=index;
if (index==self.imagesData.count-1) {
index=0;
}else{
index++;
}
[self TAPageControl:self.customPageControl2 didSelectPageAtIndex:index];
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSInteger pageIndex = scrollView.contentOffset.x/CGRectGetWidth(scrollView.frame);
self.customPageControl2.currentPage = pageIndex;
index=pageIndex;
}
// Example of use of delegate for second scroll view to respond to bullet touch event
- (void)TAPageControl:(TAPageControl *)pageControl didSelectPageAtIndex:
(NSInteger)currentIndex
{
index=currentIndex;
[self.scrollView scrollRectToVisible:CGRectMake(CGRectGetWidth(self.view.frame) * currentIndex, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.scrollView.frame)) animated:YES];
}
如果删除计时器代码,您是否看到滑块中的图像?我的意思是,只需添加一张图片,看看它是否在那里,然后从那里继续前进。 –
静态图像显示在屏幕上,但我传递的图像阵列不可见。 @JohnnyRockex –
@HamzaImran为什么你不使用UICollectionView? – Tuhin