8

I have set images in iCarousel. When I scroll the carousel, it shows images in front and back. I do not want to display images in back. Please help. Thank you.

2
  • have u used sample code of iCarousael then it also provide different switch type from that u can change the type which will not shows image in background Feb 21, 2012 at 12:44
  • please explain more thoroughly..
    – DJPlayer
    Feb 21, 2012 at 12:54

6 Answers 6

8

You should implement the delegate:

- (CGFloat)carousel:(iCarousel *)_carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value{
 switch (option)
 {
    case iCarouselOptionVisibleItems:
    {
        return numberOfItemsIntheFront;
    }
 }
}
4

You'll need to change to a custom carousel type, and copy the implementation of iCarouselTypeRotary in your delegate. Then implement -carousel:itemAlphaForOffset: so that items around the back have an alpha of zero.

2
  • Great to hear. If my answer helped, please could you click the tick mark to mark this as the correct answer?
    – Simon
    Feb 22, 2012 at 13:44
  • 1
    can you please give more description on this @Simon
    – bLacK hoLE
    Sep 15, 2015 at 8:47
3

In the latest version of iCarousel, the easiest way to do this is to set view.layer.doubleSided = NO on your carousel item views, or to use the iCarouselOptionShowBackfaces property, like this:

- (CGFloat)carousel:(iCarousel *)_carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value
{
    switch (option)
    {
        case iCarouselOptionShowBackfaces:
        {
            return NO;
        }
        default:
        {
            return value;
        }
    }
 }
2
  • 2
    I tried this but the views are still visible. If I understand the question correctly, the OP (and myself) are trying to hide the views that are behind the front views.
    – daveMac
    Apr 24, 2014 at 13:41
  • Try setting the iCarouselOptionShowBackfaces to NO. Apr 24, 2014 at 14:50
2

Code below will nicely fade away items that are going to the back. Enjoy.

func carousel(carousel: iCarousel, valueForOption option: iCarouselOption, withDefault value: CGFloat) -> CGFloat
{
    if (option == .Spacing)
    {
        return value * 1.1
    }
    else if (option == .FadeMin)
    {
        return 0;
    }
    else if (option == .FadeMax)
    {
        return 0;
    }
    else if (option == .FadeRange)
    {
        return 3;
    }

    return value
}
0

I tried the solution suggested by @NickLockwood but doesn't seem to work :-( I added it to both methods in viewForItemAtIndex & placeholderViewAtIndex. My image size is 115*115 pixels and canvas size is 146*146 pixels. However, setting a return value of 'return value * 0.82f;' under iCarouselOptionSpacing (inside the method valueForOption) did the trick for me.

1
  • It sounds like you're trying to solve a different problem than the one asked in the question. I don't see how changing the spacing could affect whether backward-facing items are visible o_O Feb 27, 2014 at 11:42
0

The easiest way to hide the background images

 func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
    switch option {
    case .spacing:
        
        return 1.05
        
    case .visibleItems:
        
        return 3

    default:
        return value
  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.