### CocoaPods Installation for CardCarousel Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md This snippet shows the necessary configuration for installing the CardCarousel library using CocoaPods. Ensure your platform is set to iOS 12.0 or higher and frameworks are enabled. ```ruby source 'https://github.com/CocoaPods/Specs.git' platform :ios, '12.0' use_frameworks! target '' do pod 'CardCarousel', '~> 2.0' end ``` -------------------------------- ### Basic CardCarousel with Local Images (UIKit) Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Demonstrates the basic setup of CardCarousel in UIKit using local images. Ensure you import the CardCarousel library. ```swift import CardCarousel let cardCarousel = CardCarousel(frame: ...).add(to: view) // For local images, you can directly assign an array of UIImage objects. cardCarousel.items = [UIImage] ``` -------------------------------- ### Custom Page Control Implementation (UIKit) Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Defines protocols for custom page control types in CardCarousel and shows an example of extending UIPageControl and implementing a custom page control with specific styling and positioning. ```swift public protocol CardCarouselPageControlType: UIView { var numberOfPages: Int { get set } var currentPage: Int { get } } public protocol CardCarouselNormalPageControlType: CardCarouselPageControlType { var currentPage: Int { get set } } public protocol CardCarouselContinousPageControlType: CardCarouselPageControlType { var progress: Double { get set } } extension UIPageControl: CardCarouselNormalPageControlType { } extension CustomPageControl: CardCarouselContinousPageControlType { // ... implementation details ... } CardCarousel(itemsPublisher: $items) { Text(itemIdentifier.text) .font(.title) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(itemIdentifier.color) } .cardLayoutSize(widthDimension: .fractionalWidth(0.9), heightDimension: .absolute(200)) .minimumLineSpacing(20) .scrollStopAlignment(.head(offset: 10)) .pageControl(makePageControl: { let pageControl = CustomPageControl() pageControl.currentPageTintColor = .white pageControl.tintColor = .green pageControl.radius = 4 pageControl.padding = 15 return pageControl }, position: .centerXBottom(offset: CGPoint(x: 0, y: -10))) .add(to: view) ``` -------------------------------- ### Custom Cell and Layout Configuration (UIKit) Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Illustrates how to use a custom cell with CardCarousel, configure layout size, transform mode, corner radius, and add it to a view with specific layout constraints. ```swift CardCarousel(items: items) { (cell: CustomCell, index: Int, itemIdentifier: Item) in cell.imageView.kf.setImage(with: url) cell.indexLabel.backgroundColor = itemIdentifier.color cell.indexLabel.text = itemIdentifier.index } .cardLayoutSize(widthDimension: .fractionalWidth(0.7), heightDimension: .fractionalHeight(0.7)) .cardTransformMode(.liner(minimumAlpha: 0.3)) .cardCornerRadius(10) .add(to: view, layoutConstraints: { cardCarouselView, superView in NSLayoutConstraint.activate([ cardCarouselView.leadingAnchor.constraint(equalTo: superView.leadingAnchor), cardCarouselView.trailingAnchor.constraint(equalTo: superView.trailingAnchor), cardCarouselView.topAnchor.constraint(equalTo: superView.topAnchor, constant: 100), cardCarouselView.heightAnchor.constraint(equalToConstant: 200) ]) }) ``` -------------------------------- ### CardCarousel with Remote Images (UIKit) Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Shows how to configure ImageLoadingManager for remote images using Kingfisher and then assign URL strings to CardCarousel items. This requires setting up loading, prefetching, and cancellation behaviors. ```swift import Kingfisher ImageLoadingManager.shared.configure { imageView.kf.setImage(with: url, placeholder: placeholder) { _ in completion() } } prefetch: { ImagePrefetcher(urls: urls).start() } cancel: { ImagePrefetcher(urls: urls).stop() } cardCarousel.items = [ "https://example.com/image1.jpg", "https://example.com/image2.jpg", "https://example.com/image3.jpg" ] ``` -------------------------------- ### SwiftUI CardCarousel View Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Demonstrates using CardCarousel within a SwiftUI view. It shows how to define content for each card and apply various modifiers for scrolling, transformation, layout, and spacing. ```swift struct Content: View { @State var items = [ "飞光飞光 劝尔一杯酒", "吾不识青天高 黄地厚", "惟见月寒日暖 来煎人寿", "食熊则肥 食蛙则瘦", ] var body: some View { CardCarouselView($items, content: { index, itemIdentifier in if index.isMultiple(of: 2) { ZStack { Color.blue Text(itemIdentifier) } } else { Text(itemIdentifier) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color.yellow) .clipShape(Capsule()) } }) .scrollMode(.automatic(timeInterval: 3)) .cardTransformMode(.coverflow(minimumAlpha: 0.3)) .cardLayoutSize(widthDimension: .fractionalWidth(0.7), heightDimension: .fractionalHeight(0.7)) .minimumLineSpacing(-20) .cardCornerRadius(10) // The larger the value, the further the slide after the user releases the drag, default is 0.9924. .decelerationRate(0.999) .onCardSelected({ index in print(index) }) .onCardChanged({ index in print(index) }) .frame(height: 200) } } ``` -------------------------------- ### cardLayoutSize Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Configures the size dimensions for the card layout. By default, it fills the entire super view. ```APIDOC ## cardLayoutSize ### Description Sets the width and height dimensions for the card layout. The default behavior is to fill the entire super view. ### Method `cardLayoutSize(widthDimension: CardLayoutDimension, heightDimension: CardLayoutDimension) -> Self` ### Parameters * **widthDimension** (CardLayoutDimension) - The dimension for the width. * **heightDimension** (CardLayoutDimension) - The dimension for the height. ``` -------------------------------- ### minimumLineSpacing Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Sets the minimum spacing between cards. The default value is 0. ```APIDOC ## minimumLineSpacing ### Description Configures the minimum spacing between adjacent cards in the carousel. Defaults to 0. ### Method `minimumLineSpacing(_ spacing: CGFloat) -> Self` ### Parameters * **spacing** (CGFloat) - The minimum spacing value. ``` -------------------------------- ### autoScrollAnimation Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Sets the animation effect for automatic scrolling. The default is `.system`. ```APIDOC ## autoScrollAnimation ### Description Configures the animation options used for automatic scrolling behavior. The default animation option is `.system`. ### Method `autoScrollAnimation(_ animationOptions: CardScrollAnimationOptions) -> Self` ### Parameters * **animationOptions** (CardScrollAnimationOptions) - The animation options for auto-scrolling. ``` -------------------------------- ### Set Minimum Line Spacing Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Defines the minimum spacing between cards. The default value is 0. ```swift func minimumLineSpacing(_ spacing: CGFloat) -> Self ``` -------------------------------- ### singleCardAlignment Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Sets the alignment for a single card scenario. The default is center alignment. ```APIDOC ## singleCardAlignment ### Description Specifies the alignment of a card when there is only a single card present in the carousel. The default alignment is centered. ### Method `singleCardAlignment(_ alignment: CardScrollStopAlignment) -> Self` ### Parameters * **alignment** (CardScrollStopAlignment) - The alignment mode for a single card (e.g., `.center`, `.head`). ``` -------------------------------- ### Set Card Paging Threshold Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Sets the threshold for card paging, which is half the default card width. Options include fractional and absolute values. ```swift func cardPagingThreshold(_ threshold: CardPagingThreshold) -> Self ``` -------------------------------- ### loopMode Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Configures the loop mode for the carousel. The default is `.circular`. ```APIDOC ## loopMode ### Description Specifies the looping behavior of the carousel. The default mode is circular, meaning it seamlessly loops back to the beginning after the last item. ### Method `loopMode(_ mode: CardLoopMode) -> Self` ### Parameters * **mode** (CardLoopMode) - The loop mode (e.g., `.circular`, `.rollback`, `.single`). ``` -------------------------------- ### pagingThreshold Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Sets the threshold for card paging, which defaults to half the card width. ```APIDOC ## pagingThreshold ### Description Defines the threshold for triggering card paging. By default, this threshold is set to half the width of a card. ### Method `pagingThreshold(_ threshold: CGFloat) -> Self` ### Parameters * **threshold** (CGFloat) - The paging threshold value. This can be specified as fractional or absolute. ``` -------------------------------- ### Set Single Card Alignment Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Configures the alignment for a single card when it is displayed. The default alignment is center. ```swift func singleCardAlignment(_ alignment: CardScrollStopAlignment) -> Self ``` -------------------------------- ### cardTransformMode Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Defines the transformation effect applied to cards. The default is `.none`. ```APIDOC ## cardTransformMode ### Description Specifies the visual transformation mode for the cards. The default is `.none`. ### Method `cardTransformMode(_ mode: CardTransformMode) -> Self` ### Parameters * **mode** (CardTransformMode) - The transformation mode to apply (e.g., `.liner`, `.coverflow`). ``` -------------------------------- ### Set Card Layout Size Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Configures the dimensions of the cards within the carousel. By default, cards fill the entire super view. ```swift func cardLayoutSize(widthDimension: CardLayoutDimension, heightDimension: CardLayoutDimension) -> Self ``` -------------------------------- ### Set Auto Scroll Animation Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Configures the animation effect for automatic scrolling. The default is .system. ```swift func autoScrollAnimation(_ animationOptions: CardScrollAnimationOptions) -> Self ``` -------------------------------- ### scrollMode Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Defines the scrolling mode, which can be automatic or manual. The default is `.automatic(timeInterval: 3)`. ```APIDOC ## scrollMode ### Description Sets the mode for scrolling, determining whether it's automatic or manual. The default is automatic scrolling with a 3-second interval. Note: When using spell invocation, the time interval can only be an integer. ### Method `scrollMode(_ mode: CardScrollMode) -> Self` ### Parameters * **mode** (CardScrollMode) - The scrolling mode, which can be `.automatic(timeInterval: TimeInterval)` or `.manual`. ``` -------------------------------- ### sideMargin Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Sets the margin on both sides of the sliding direction. This is effective only when the loop mode is not circular. The default is 0. ```APIDOC ## sideMargin ### Description Sets the margin on the leading and trailing edges of the carousel's scrollable area. This setting is only applicable when the `loopMode` is not set to `.circular`. The default value is 0. ### Method `sideMargin(_ margin: CGFloat) -> Self` ### Parameters * **margin** (CGFloat) - The margin value for both sides. ``` -------------------------------- ### scrollStopAlignment Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Determines the alignment of cards when scrolling stops. The default is center alignment. ```APIDOC ## scrollStopAlignment ### Description Defines how cards are aligned within the carousel view once the scrolling action naturally stops. The default alignment is centered. ### Method `scrollStopAlignment(_ alignment: CardScrollStopAlignment) -> Self` ### Parameters * **alignment** (CardScrollStopAlignment) - The alignment mode (e.g., `.center`, `.head`). ``` -------------------------------- ### Set Scroll Stop Alignment Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Determines the alignment of cards when scrolling stops. The default alignment is center. ```swift func scrollStopAlignment(_ alignment: CardScrollStopAlignment) -> Self ``` -------------------------------- ### Set Loop Mode Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Specifies the looping behavior of the carousel. The default mode is .circular. ```swift func loopMode(_ mode: CardLoopMode) -> Self ``` -------------------------------- ### Set Card Transform Mode Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Specifies the transformation effect applied to cards during scrolling. The default mode is .none. ```swift func cardTransformMode(_ mode: CardTransformMode) -> Self ``` -------------------------------- ### scrollDirection Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Configures the direction of scrolling for the carousel. The default is `.leftToRight`. ```APIDOC ## scrollDirection ### Description Determines the scrolling direction of the card carousel. The default direction is left to right. ### Method `scrollDirection(_ direction: CardScrollDirection) -> Self` ### Parameters * **direction** (CardScrollDirection) - The scrolling direction (e.g., `.leftToRight`, `.rightToLeft`, `.topToBottom`, `.bottomToTop`). ``` -------------------------------- ### Set Side Margin Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Sets the margin on both sides of the sliding direction. This is effective only when the loopMode is not circular. The default margin is 0. ```swift func sideMargin(_ margin: CGFloat) -> Self ``` -------------------------------- ### disableCurrentCardAlwaysOnTop Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Disables the behavior where the current card always remains at the forefront. This may allow it to be obscured by other cards. ```APIDOC ## disableCurrentCardAlwaysOnTop ### Description Disables the feature that keeps the currently active card always on top. When disabled, other cards might visually overlap the current card. ### Method `disableCurrentCardAlwaysOnTop() -> Self` ``` -------------------------------- ### Set Scroll Direction Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Specifies the direction of scrolling for the carousel. The default direction is .leftToRight. ```swift func scrollDirection(_ direction: CardScrollDirection) -> Self ``` -------------------------------- ### Disable Current Card Always On Top Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Removes the default behavior where the current card is always at the forefront. Invoking this may cause the current card to be obscured by others. ```swift func disableCurrentCardAlwaysOnTop() -> Self ``` -------------------------------- ### Set Scroll Mode Source: https://github.com/yuleifuyun/cardcarousel/blob/main/README.md Defines whether the carousel scrolls automatically or manually. The default is .automatic with a 3-second interval. Note: When using '咒语' (incantations), the time interval must be an integer. ```swift func scrollMode(_ mode: CardScrollMode) -> Self ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.