Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to adjust the spacing between the item? #787

Open
charlesYun opened this issue Mar 2, 2017 · 4 comments
Open

How to adjust the spacing between the item? #787

charlesYun opened this issue Mar 2, 2017 · 4 comments

Comments

@charlesYun
Copy link

How to adjust the spacing between the item?

@andreyrd
Copy link

andreyrd commented Mar 2, 2017

You can implement this iCarouselDelegate method

func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat

and return a value for iCarouselOptionSpacing like so:

func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
    switch (option) {
        case .spacing: return 8 // 8 points spacing
        default: return value
    }
}

Another way to add spacing between items, but only if you are using a custom transform, is to transform the x position of the items based on the offset:

func carousel(
    _ carousel: iCarousel,
    itemTransformForOffset offset: CGFloat,
    baseTransform transform: CATransform3D
) -> CATransform3D {
    return CATransform3DTranslate(
        transform, // base
        offset * 1.15 * carousel.itemWidth, // x
        0, // y
        0 // z
    )
}

Specifically the 1.15 on the x-axis is what gives my items spacing.

All code snippets are in Swift 3.0

@charlesYun
Copy link
Author

Thank you very much for your answer, but my code is based on the OC

@charlesYun
Copy link
Author

I can find the answer from your answer, thank you very much

@hb2708
Copy link

hb2708 commented Jul 23, 2017

@caoyunxiao If your problem is solved please feel free to close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants