I’m trying to implement a uiscrollview with small images.
-
I need that uiscrollview last image in every end remain in the center when scroll finishes, leaving one side empty. Now last image remain in the sides when scroll finishes.
-
I need to know which image is in the center of the scollview, to apply a shadow on it,
jugadorSlide.pagingEnabled = YES; NSError *error = nil; fotosJugadores = [[NSFileManager defaultManager] contentsOfDirectoryAtPath: @"/Users/exular/Developer/GBC/exular/GBC/Caras/" error: &error]; NSInteger numberOfViews = [fotosJugadores count]; for (int i = 0; i < numberOfViews; i++) { UIImage *myImage = [UIImage imageNamed:[fotosJugadores objectAtIndex:i]]; CGFloat yOrigin = i * myImage.size.width; UIImageView *awesomeView = [[UIImageView alloc] initWithFrame:CGRectMake(yOrigin, 0, myImage.size.width, myImage.size.height)]; awesomeView.alpha = 0.5; awesomeView.image = myImage; [self.jugadorSlide addSubview:awesomeView]; awesomeView=nil; } jugadorSlide .contentSize = CGSizeMake(65 * numberOfViews,78); jugadorSlide.layer.cornerRadius = 11; jugadorSlide.layer.masksToBounds = YES;
Many thanks for your help.
To allow the first and last image to be in the center just add an empty space before the first image and after your last image. In other words: start your
yOriginat65and add65to thecontentSizewidth (I am assuming that65is your images width):To find out which image is in the center add the following inside the UIScrollViewDelegate method
scrollViewDidEndDecelerating:.To easily get the currentImage, add tags to your images when you create them: