### Getting Started with FSPagerView Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md Instructions on how to initialize and set up FSPagerView programmatically or using Interface Builder. ```APIDOC ## Getting Started with FSPagerView ### Programmatic Setup This section demonstrates how to create and configure an `FSPagerView` instance in your code. ```objc // Create a pager view FSPagerView *pagerView = [[FSPagerView alloc] initWithFrame:frame1]; pagerView.dataSource = self; pagerView.delegate = self; [pagerView registerClass:[FSPagerViewCell class] forCellWithReuseIdentifier:@"cell"]; [self.view addSubview:pagerView]; // Create a page control FSPageControl *pageControl = [[FSPageControl alloc] initWithFrame:frame2]; [self.view addSubview:pageControl]; ``` ### Interface Builder Setup To use `FSPagerView` with Interface Builder, follow these steps: 1. Drag a **UIView** instance into your View Controller. 2. Change its `Custom Class` to `FSPagerView` (or `FSPageControl`). 3. Link the `dataSource` and `delegate` properties of the `FSPagerView` to your View Controller. 4. Register a cell class in `viewDidLoad`. ```objc - (void)viewDidLoad { super viewDidLoad]; [self.pagerView registerClass:[FSPagerViewCell class] forCellWithReuseIdentifier:@"cell"]; } ``` ``` -------------------------------- ### Programmatic Setup Source: https://context7.com/wenchaod/fspagerview/llms.txt Demonstrates how to create and configure an FSPagerView and FSPageControl programmatically in a UIViewController. ```APIDOC ## Programmatic Setup Create FSPagerView programmatically without Interface Builder. ### Description This section shows how to instantiate `FSPagerView` and `FSPageControl` in code, set their frames, assign data sources and delegates, and register cells. ### Method Programmatic Initialization ### Endpoint N/A (Client-side code) ### Parameters N/A ### Request Example ```swift import UIKit class ProgrammaticViewController: UIViewController, FSPagerViewDataSource, FSPagerViewDelegate { var pagerView: FSPagerView! var pageControl: FSPageControl! let images = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"] override func viewDidLoad() { super.viewDidLoad() // Create pager view let pagerFrame = CGRect(x: 0, y: 100, width: view.bounds.width, height: 300) pagerView = FSPagerView(frame: pagerFrame) pagerView.dataSource = self pagerView.delegate = self pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell") view.addSubview(pagerView) // Create page control let controlFrame = CGRect(x: 0, y: 380, width: view.bounds.width, height: 30) pageControl = FSPageControl(frame: controlFrame) pageControl.numberOfPages = images.count pageControl.contentHorizontalAlignment = .center view.addSubview(pageControl) } func numberOfItems(in pagerView: FSPagerView) -> Int { return images.count } func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell { let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) cell.imageView?.image = UIImage(named: images[index]) cell.imageView?.contentMode = .scaleAspectFill cell.imageView?.clipsToBounds = true return cell } func pagerViewDidScroll(_ pagerView: FSPagerView) { pageControl.currentPage = pagerView.currentIndex } } ``` ### Response N/A (Client-side code setup) ``` -------------------------------- ### Carthage Installation Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Specify the FSPagerView repository in your Cartfile for Carthage integration. ```ruby github "WenchaoD/FSPagerView" ``` -------------------------------- ### Setup FSPageControl Source: https://context7.com/wenchaod/fspagerview/llms.txt Configures the page control indicator and synchronizes it with pager view scroll events. ```swift @IBOutlet weak var pageControl: FSPageControl! { didSet { // Set number of pages pageControl.numberOfPages = 7 // Set current page pageControl.currentPage = 0 // Horizontal alignment: .left, .center, .right pageControl.contentHorizontalAlignment = .center // Content insets pageControl.contentInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20) // Hide for single page pageControl.hidesForSinglePage = true // Spacing configuration pageControl.itemSpacing = 8 // Size of each indicator pageControl.interitemSpacing = 6 // Space between indicators } } // Update page control when pager view scrolls func pagerViewWillEndDragging(_ pagerView: FSPagerView, targetIndex: Int) { pageControl.currentPage = targetIndex } ``` -------------------------------- ### Programmatic FSPagerView Setup Source: https://context7.com/wenchaod/fspagerview/llms.txt Create and configure an FSPagerView and FSPageControl programmatically within a UIViewController. Ensure the view controller conforms to FSPagerViewDataSource and FSPagerViewDelegate. ```swift import UIKit class ProgrammaticViewController: UIViewController, FSPagerViewDataSource, FSPagerViewDelegate { var pagerView: FSPagerView! var pageControl: FSPageControl! let images = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"] override func viewDidLoad() { super.viewDidLoad() // Create pager view let pagerFrame = CGRect(x: 0, y: 100, width: view.bounds.width, height: 300) pagerView = FSPagerView(frame: pagerFrame) pagerView.dataSource = self pagerView.delegate = self pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell") view.addSubview(pagerView) // Create page control let controlFrame = CGRect(x: 0, y: 380, width: view.bounds.width, height: 30) pageControl = FSPageControl(frame: controlFrame) pageControl.numberOfPages = images.count pageControl.contentHorizontalAlignment = .center view.addSubview(pageControl) } func numberOfItems(in pagerView: FSPagerView) -> Int { return images.count } func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell { let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) cell.imageView?.image = UIImage(named: images[index]) cell.imageView?.contentMode = .scaleAspectFill cell.imageView?.clipsToBounds = true return cell } func pagerViewDidScroll(_ pagerView: FSPagerView) { pageControl.currentPage = pagerView.currentIndex } } ``` -------------------------------- ### Cocoapods Installation Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Add FSPagerView to your project using Cocoapods by including this line in your Podfile. ```ruby use_frameworks! target '' do pod 'FSPagerView' end ``` -------------------------------- ### Basic FSPagerView Setup in Swift Source: https://context7.com/wenchaod/fspagerview/llms.txt Implement a basic banner view controller using FSPagerView and FSPageControl. Ensure your view controller conforms to FSPagerViewDataSource and FSPagerViewDelegate protocols. Register a cell class for reuse and configure the pager view and page control properties. ```swift import UIKit class BannerViewController: UIViewController, FSPagerViewDataSource, FSPagerViewDelegate { let imageNames = ["banner1.jpg", "banner2.jpg", "banner3.jpg", "banner4.jpg", "banner5.jpg"] @IBOutlet weak var pagerView: FSPagerView! { didSet { // Register cell class for reuse self.pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell") self.pagerView.itemSize = FSPagerView.automaticSize } } @IBOutlet weak var pageControl: FSPageControl! { didSet { self.pageControl.numberOfPages = self.imageNames.count self.pageControl.contentHorizontalAlignment = .right self.pageControl.contentInsets = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20) } } // MARK: - FSPagerViewDataSource func numberOfItems(in pagerView: FSPagerView) -> Int { return self.imageNames.count } func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell { let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) cell.imageView?.image = UIImage(named: self.imageNames[index]) cell.imageView?.contentMode = .scaleAspectFill cell.imageView?.clipsToBounds = true cell.textLabel?.text = "Slide \(index + 1)" return cell } // MARK: - FSPagerViewDelegate func pagerView(_ pagerView: FSPagerView, didSelectItemAt index: Int) { pagerView.deselectItem(at: index, animated: true) pagerView.scrollToItem(at: index, animated: true) print("Selected item at index: \(index)") } func pagerViewWillEndDragging(_ pagerView: FSPagerView, targetIndex: Int) { self.pageControl.currentPage = targetIndex } func pagerViewDidEndScrollAnimation(_ pagerView: FSPagerView) { self.pageControl.currentPage = pagerView.currentIndex } } ``` -------------------------------- ### Swift Package Manager Installation for FSPagerView Source: https://context7.com/wenchaod/fspagerview/llms.txt Include FSPagerView in your project using Swift Package Manager by adding the package URL to your Package.swift file. ```swift dependencies: [ .package(url: "https://github.com/WenchaoD/FSPagerView.git", from: "0.8.0") ] ``` -------------------------------- ### FSPagerViewDelegate: Will Begin Dragging Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md This delegate method is called when the user begins to drag the pager view content. It signals the start of a scrolling gesture. ```objc - (void)pagerViewWillBeginDragging:(FSPagerView *)pagerView; ``` -------------------------------- ### Register Custom Cells for FSPagerView Source: https://context7.com/wenchaod/fspagerview/llms.txt Register cell classes or nib files for reuse. Use `dequeueReusableCell` in your data source to get cells. ```swift // Register cell class pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell") ``` ```swift // Register custom cell class pagerView.register(CustomPagerCell.self, forCellWithReuseIdentifier: "customCell") ``` ```swift // Register nib let nib = UINib(nibName: "CustomPagerCell", bundle: nil) pagerView.register(nib, forCellWithReuseIdentifier: "customCell") ``` ```swift // Dequeue cell in data source func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell { let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) // Configure cell... return cell } ``` -------------------------------- ### Programmatic Navigation and Cell Management Source: https://context7.com/wenchaod/fspagerview/llms.txt Control pager view behavior programmatically using these navigation methods. Useful for custom interactions or initial setup. ```swift // Scroll to specific item pagerView.scrollToItem(at: 2, animated: true) ``` ```swift // Select item pagerView.selectItem(at: 3, animated: true) ``` ```swift // Deselect item pagerView.deselectItem(at: 3, animated: true) ``` ```swift // Reload all data pagerView.reloadData() ``` ```swift // Get index for a cell if let cell = visibleCell { let index = pagerView.index(for: cell) // Returns NSNotFound if not found } ``` ```swift // Get cell at specific index (returns nil if not visible) if let cell = pagerView.cellForItem(at: 2) { // Configure visible cell } ``` ```swift // Access current index let currentIndex = pagerView.currentIndex ``` ```swift // Check if user is tracking (touching) let isTracking = pagerView.isTracking ``` ```swift // Get scroll offset (percentage position) let scrollOffset = pagerView.scrollOffset ``` ```swift // Access pan gesture recognizer for custom handling let panGesture = pagerView.panGestureRecognizer ``` -------------------------------- ### Register Cell Class for FSPagerView in Interface Builder Setup Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md When using FSPagerView with Interface Builder, you need to register your cell class within the viewDidLoad method. This ensures that the pager view can dequeue reusable cells correctly. ```objc - (void)viewDidLoad { [super viewDidLoad]; [self.pagerView registerClass:[FSPagerViewCell class] forCellWithReuseIdentifier:@"cell"]; } ``` -------------------------------- ### Implement FSPagerView in Objective-C Source: https://context7.com/wenchaod/fspagerview/llms.txt Demonstrates initializing the pager view, configuring properties, setting up the page control, and implementing required data source and delegate methods. ```objc // Import the module @import FSPagerView; // Create pager view FSPagerView *pagerView = [[FSPagerView alloc] initWithFrame:frame]; pagerView.dataSource = self; pagerView.delegate = self; [pagerView registerClass:[FSPagerViewCell class] forCellWithReuseIdentifier:@"cell"]; [self.view addSubview:pagerView]; // Configure properties pagerView.automaticSlidingInterval = 3.0; pagerView.isInfinite = YES; pagerView.itemSize = CGSizeMake(200, 180); pagerView.interitemSpacing = 10; pagerView.decelerationDistance = 2; // Apply transformer pagerView.transformer = [[FSPagerViewTransformer alloc] initWithType:FSPagerViewTransformerTypeCoverFlow]; // Create page control FSPageControl *pageControl = [[FSPageControl alloc] initWithFrame:frame2]; pageControl.numberOfPages = 7; pageControl.currentPage = 0; pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight; [self.view addSubview:pageControl]; // Customize page control [pageControl setStrokeColor:[UIColor greenColor] forState:UIControlStateNormal]; [pageControl setStrokeColor:[UIColor greenColor] forState:UIControlStateSelected]; [pageControl setFillColor:[UIColor greenColor] forState:UIControlStateSelected]; // Data source implementation - (NSInteger)numberOfItemsInPagerView:(FSPagerView *)pagerView { return self.imageNames.count; } - (FSPagerViewCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index { FSPagerViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"cell" atIndex:index]; cell.imageView.image = [UIImage imageNamed:self.imageNames[index]]; cell.imageView.contentMode = UIViewContentModeScaleAspectFill; cell.imageView.clipsToBounds = YES; cell.textLabel.text = [NSString stringWithFormat:@"Slide %ld", (long)index + 1]; return cell; } // Delegate implementation - (void)pagerView:(FSPagerView *)pagerView didSelectItemAtIndex:(NSInteger)index { [pagerView deselectItemAtIndex:index animated:YES]; [pagerView scrollToItemAtIndex:index animated:YES]; } - (void)pagerViewWillEndDragging:(FSPagerView *)pagerView targetIndex:(NSInteger)index { self.pageControl.currentPage = index; } ``` -------------------------------- ### FSPagerView Implementation Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Guidelines for setting up FSPagerView using code or Interface Builder and implementing the required data source methods. ```APIDOC ## FSPagerView Implementation ### Description Steps to initialize FSPagerView and implement the necessary data source methods for displaying content. ### Implementation - **Initialization**: Create an instance of FSPagerView, set the dataSource and delegate, and register a cell class. - **Data Source**: Implement `numberOfItems(in:)` to return the total count and `pagerView(_:cellForItemAt:)` to configure and return a `FSPagerViewCell`. ``` -------------------------------- ### Create and Configure FSPagerView and FSPageControl Programmatically Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Initialize and set up FSPagerView and FSPageControl instances, assigning data sources and delegates, and registering cells. ```swift // Create a pager view let pagerView = FSPagerView(frame: frame1) pagerView.dataSource = self pagerView.delegate = self pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell") self.view.addSubview(pagerView) // Create a page control let pageControl = FSPageControl(frame: frame2) self.view.addSubview(pageControl) ``` -------------------------------- ### Highlight Item Delegate Methods Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Methods to manage item highlighting during tracking. ```swift func pagerView(_ pagerView: FSPagerView, shouldHighlightItemAt index: Int) -> Bool ``` ```swift func pagerView(_ pagerView: FSPagerView, didHighlightItemAt index: Int) ``` -------------------------------- ### Configure FSPagerView with Interface Builder Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Set up FSPagerView in Interface Builder by changing the Custom Class and linking delegate/dataSource outlets, then register a cell. ```swift @IBOutlet weak var pagerView: FSPagerView! { didSet { self.pagerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell") } } ``` -------------------------------- ### Create FSPagerView and FSPageControl Programmatically Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md This snippet demonstrates how to initialize and configure an FSPagerView and an FSPageControl programmatically. Ensure you set the dataSource and delegate for the pager view and register a cell class before adding it to the view hierarchy. ```objc // Create a pager view FSPagerView *pagerView = [[FSPagerView alloc] initWithFrame:frame1]; pagerView.dataSource = self; pagerView.delegate = self; [pagerView registerClass:[FSPagerViewCell class] forCellWithReuseIdentifier:@"cell"]; [self.view addSubview:pagerView]; // Create a page control FSPageControl *pageControl = [[FSPageControl alloc] initWithFrame:frame2]; [self.view addSubview:pageControl]; ``` -------------------------------- ### Implement FSPagerViewDelegate Methods Source: https://context7.com/wenchaod/fspagerview/llms.txt Implement these delegate methods to handle user interactions and scroll events. Return false to prevent default behaviors like highlighting or selection. ```swift class ViewController: UIViewController, FSPagerViewDelegate { // Called to determine if the item should be highlighted during tracking func pagerView(_ pagerView: FSPagerView, shouldHighlightItemAt index: Int) -> Bool { return true // Return false to prevent highlighting } // Called when an item is highlighted func pagerView(_ pagerView: FSPagerView, didHighlightItemAt index: Int) { print("Highlighted item at index: \(index)") } // Called to determine if the specified item should be selected func pagerView(_ pagerView: FSPagerView, shouldSelectItemAt index: Int) -> Bool { return true // Return false to prevent selection } // Called when an item is selected func pagerView(_ pagerView: FSPagerView, didSelectItemAt index: Int) { pagerView.deselectItem(at: index, animated: true) pagerView.scrollToItem(at: index, animated: true) print("Selected item at index: \(index)") } // Called when a cell is about to be displayed func pagerView(_ pagerView: FSPagerView, willDisplay cell: FSPagerViewCell, forItemAt index: Int) { print("Will display cell at index: \(index)") } // Called when a cell was removed from the pager view func pagerView(_ pagerView: FSPagerView, didEndDisplaying cell: FSPagerViewCell, forItemAt index: Int) { print("Did end displaying cell at index: \(index)") } // Called when scrolling is about to start func pagerViewWillBeginDragging(_ pagerView: FSPagerView) { print("Will begin dragging") } // Called when the user finishes scrolling func pagerViewWillEndDragging(_ pagerView: FSPagerView, targetIndex: Int) { print("Will end dragging, target index: \(targetIndex)") pageControl.currentPage = targetIndex } // Called when scrolling occurs func pagerViewDidScroll(_ pagerView: FSPagerView) { // Use scrollOffset for precise position tracking let offset = pagerView.scrollOffset print("Scroll offset: \(offset)") } // Called when a scrolling animation concludes func pagerViewDidEndScrollAnimation(_ pagerView: FSPagerView) { print("Did end scroll animation, current index: \(pagerView.currentIndex)") pageControl.currentPage = pagerView.currentIndex } // Called when deceleration ends after scrolling func pagerViewDidEndDecelerating(_ pagerView: FSPagerView) { print("Did end decelerating, current index: \(pagerView.currentIndex)") } } ``` -------------------------------- ### Implement FSPagerViewDataSource Methods Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md Implement these methods to provide the data for your FSPagerView. numberOfItemsInpagerView: returns the total number of items, and pagerView:cellForItemAtIndex: configures and returns the cell for a given index. ```objc - (NSInteger)numberOfItemsInpagerView:(FSPagerView *)pagerView { return numberOfItems; } - (FSPagerViewCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index { FSPagerViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"cell" atIndex:index]; cell.imageView.image = ...; cell.textLabel.text = ...; return cell; } ``` -------------------------------- ### FSPagerView Navigation and Properties Source: https://context7.com/wenchaod/fspagerview/llms.txt Methods and properties for controlling the pager view state, programmatic navigation, and visual configuration. ```APIDOC ## FSPagerView Navigation and Properties ### Navigation Methods - **scrollToItem(at:animated:)** - Programmatically scroll to a specific index. - **selectItem(at:animated:)** - Programmatically select an item. - **deselectItem(at:animated:)** - Programmatically deselect an item. - **reloadData()** - Refresh all data in the pager view. - **index(for:)** - Retrieve the index of a specific cell. - **cellForItem(at:)** - Retrieve the cell at a specific index. ### Configuration Properties - **isScrollEnabled** (Bool) - Enable or disable scrolling. - **bounces** (Bool) - Enable or disable bouncing. - **currentIndex** (Int) - Get the current active index. - **scrollOffset** (CGFloat) - Get the current scroll position percentage. - **removesInfiniteLoopForSingleItem** (Bool) - Configuration for infinite loop behavior. ``` -------------------------------- ### Select Item Delegate Methods Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Methods to manage item selection within the pager view. ```swift func pagerView(_ pagerView: FSPagerView, shouldSelectItemAt index: Int) -> Bool ``` ```swift func pagerView(_ pagerView: FSPagerView, didSelectItemAt index: Int) ``` -------------------------------- ### FSPagerViewDataSource Implementation Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md Implement the `FSPagerViewDataSource` protocol to provide data for the pager view. ```APIDOC ## Implement FSPagerViewDataSource To populate the pager view with content, you need to implement the `FSPagerViewDataSource` protocol. ### Required Methods - **numberOfItemsInpagerView:** Returns the total number of items in the pager view. ```objc - (NSInteger)numberOfItemsInpagerView:(FSPagerView *)pagerView { return numberOfItems; } ``` - **pagerView:cellForItemAtIndexPath:** Returns a configured cell for the specified index. ```objc - (FSPagerViewCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index { FSPagerViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"cell" atIndex:index]; cell.imageView.image = ...; cell.textLabel.text = ...; return cell; } ``` ``` -------------------------------- ### isInfinite Property Source: https://context7.com/wenchaod/fspagerview/llms.txt Enables or disables infinite scrolling behavior. ```APIDOC ## isInfinite Property A boolean value that indicates whether the pager view has infinite scrolling enabled. When true, users can scroll continuously in either direction. Default is false. ### Description This property determines if the pager view should loop infinitely. When enabled, scrolling past the last item will wrap around to the first item, and vice versa. ### Method Property Assignment ### Endpoint N/A (Client-side property) ### Parameters - **isInfinite** (Bool) - Set to `true` to enable infinite scrolling, `false` to disable. - **removesInfiniteLoopForSingleItem** (Bool) - Set to `true` to disable infinite loop when there's only one item. ### Request Example ```swift // Enable infinite scrolling pagerView.isInfinite = true // Disable infinite scrolling pagerView.isInfinite = false // Remove infinite loop for single item (useful when dynamically loading content) pagerView.removesInfiniteLoopForSingleItem = true ``` ### Response N/A (Client-side property) ``` -------------------------------- ### Implement FSPagerViewDataSource: Number of Items Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Provide the total number of items that the pager view should display. ```swift public func numberOfItems(in pagerView: FSPagerView) -> Int { return numberOfItems } ``` -------------------------------- ### Scroll Event Delegate Methods Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Methods to track scrolling, dragging, and animation states. ```swift func pagerViewWillBeginDragging(_ pagerView: FSPagerView) ``` ```swift func pagerViewWillEndDragging(_ pagerView: FSPagerView, targetIndex: Int) ``` ```swift func pagerViewDidScroll(_ pagerView: FSPagerView) ``` ```swift func pagerViewDidEndScrollAnimation(_ pagerView: FSPagerView) ``` ```swift func pagerViewDidEndDecelerating(_ pagerView: FSPagerView) ``` -------------------------------- ### FSPageControl Configuration Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Methods and properties for customizing the appearance and state of the FSPageControl component. ```APIDOC ## FSPageControl Configuration ### Description Properties and methods to manage the state and visual appearance of the page control indicators. ### Properties - **numberOfPages** (Int) - The number of page indicators. Default is 0. - **currentPage** (Int) - The current page index. Default is 0. - **contentHorizontalAlignment** (UIControlContentHorizontalAlignment) - The horizontal alignment of content. Default is center. ### Methods - **setStrokeColor:forState:** (UIColor, UIControlState) - Sets the stroke color for indicators. - **setFillColor:forState:** (UIColor, UIControlState) - Sets the fill color for indicators. - **setImage:forState:** (UIImage, UIControlState) - Sets the image for indicators. - **setPath:forState:** (UIBezierPath, UIControlState) - Sets the path for indicators. ``` -------------------------------- ### Customize FSPageControl Colors Source: https://context7.com/wenchaod/fspagerview/llms.txt Configure stroke and fill colors for page indicators. Pass nil to reset colors to their default values. ```swift // Ring style - stroke color only for normal, filled for selected pageControl.setStrokeColor(.green, for: .normal) pageControl.setStrokeColor(.green, for: .selected) pageControl.setFillColor(.green, for: .selected) // Filled style with different colors pageControl.setFillColor(.gray, for: .normal) pageControl.setFillColor(.white, for: .selected) // Custom colors let normalColor = UIColor(white: 0.7, alpha: 1.0) let selectedColor = UIColor(red: 255/255.0, green: 102/255.0, blue: 255/255.0, alpha: 1.0) pageControl.setStrokeColor(normalColor, for: .normal) pageControl.setStrokeColor(selectedColor, for: .selected) pageControl.setFillColor(selectedColor, for: .selected) // Reset colors to default pageControl.setStrokeColor(nil, for: .normal) pageControl.setStrokeColor(nil, for: .selected) pageControl.setFillColor(nil, for: .normal) pageControl.setFillColor(nil, for: .selected) ``` -------------------------------- ### FSPagerView Configuration Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Configuration options for the FSPagerView, controlling its scrolling behavior and item display. ```APIDOC ## FSPagerView Configuration Properties ### automaticSlidingInterval The time interval of automatic sliding. Set to 0 to disable automatic sliding. Default is 0. **Example:** ```swift pagerView.automaticSlidingInterval = 3.0 ``` ### isInfinite A boolean value that indicates whether the pager view has an infinite number of items. Default is false. **Example:** ```swift pagerView.isInfinite = true ``` ### decelerationDistance An unsigned integer value that determines the paging distance. It indicates the number of passing items during deceleration. When set to `FSPagerView.automaticDistance`, the actual distance is automatically calculated based on the pager view's scrolling speed. Default is 1. **Example:** ```swift pagerView.decelerationDistance = 2 ``` ### itemSize The size of each item in the pager view. When set to `FSPagerView.automaticSize`, the items fill the entire visible area of the pager view. Default is `FSPagerView.automaticSize`. **Example:** ```swift pagerView.itemSize = CGSize(width: 200, height: 180) ``` ### interitemSpacing The spacing between items in the pager view. Default is 0. **Example:** ```swift pagerView.interitemSpacing = 10 ``` ``` -------------------------------- ### Set Current Page for Page Control Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Set the currently highlighted page indicator. Defaults to 0. ```swift pageControl.currentPage = 1 ``` -------------------------------- ### Define Custom Indicator Paths Source: https://context7.com/wenchaod/fspagerview/llms.txt Use UIBezierPath to create custom shapes for indicators. The path is applied to the control using setPath. ```swift // Square indicators let squarePath = UIBezierPath(rect: CGRect(x: 0, y: 0, width: 8, height: 8)) pageControl.setPath(squarePath, for: .normal) pageControl.setPath(squarePath, for: .selected) // Oval for selected, square for normal let ovalPath = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 8, height: 8)) pageControl.setPath(squarePath, for: .normal) pageControl.setPath(ovalPath, for: .selected) // Star shape indicator func createStarPath(size: CGFloat) -> UIBezierPath { let starPath = UIBezierPath() starPath.move(to: CGPoint(x: size * 0.5, y: 0)) starPath.addLine(to: CGPoint(x: size * 0.677, y: size * 0.257)) starPath.addLine(to: CGPoint(x: size * 0.975, y: size * 0.345)) starPath.addLine(to: CGPoint(x: size * 0.785, y: size * 0.593)) starPath.addLine(to: CGPoint(x: size * 0.794, y: size * 0.905)) starPath.addLine(to: CGPoint(x: size * 0.5, y: size * 0.8)) starPath.addLine(to: CGPoint(x: size * 0.206, y: size * 0.905)) starPath.addLine(to: CGPoint(x: size * 0.215, y: size * 0.593)) starPath.addLine(to: CGPoint(x: size * 0.025, y: size * 0.345)) starPath.addLine(to: CGPoint(x: size * 0.323, y: size * 0.257)) starPath.close() return starPath } let starPath = createStarPath(size: pageControl.itemSpacing) pageControl.setStrokeColor(.yellow, for: .normal) pageControl.setStrokeColor(.yellow, for: .selected) pageControl.setFillColor(.yellow, for: .selected) pageControl.setPath(starPath, for: .normal) pageControl.setPath(starPath, for: .selected) // Heart shape indicator func createHeartPath(size: CGFloat) -> UIBezierPath { let heartPath = UIBezierPath() heartPath.move(to: CGPoint(x: size * 0.5, y: size)) heartPath.addCurve( to: CGPoint(x: 0, y: size * 0.25), controlPoint1: CGPoint(x: size * 0.5, y: size * 0.75), controlPoint2: CGPoint(x: 0, y: size * 0.5) ) heartPath.addArc( withCenter: CGPoint(x: size * 0.25, y: size * 0.25), radius: size * 0.25, startAngle: .pi, endAngle: 0, clockwise: true ) heartPath.addArc( withCenter: CGPoint(x: size * 0.75, y: size * 0.25), radius: size * 0.25, startAngle: .pi, endAngle: 0, clockwise: true ) heartPath.addCurve( to: CGPoint(x: size * 0.5, y: size), controlPoint1: CGPoint(x: size, y: size * 0.5), controlPoint2: CGPoint(x: size * 0.5, y: size * 0.75) ) heartPath.close() return heartPath } ``` -------------------------------- ### Set Path for Page Indicators Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Define the UIBezierPath for page indicators in their normal and selected states. ```swift pageControl.setPath(UIBezierPath(rect: CGRect(x: 0, y: 0, width: 8, height: 8)), for: .normal) pageControl.setPath(UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 8, height: 8)), for: .selected) ``` -------------------------------- ### FSPagerViewDelegate Methods Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Delegate methods for handling user interactions and scroll events within the FSPagerView component. ```APIDOC ## FSPagerViewDelegate Methods ### Description Methods to handle item selection, highlighting, cell display, and scroll events. ### Methods - **pagerView(_:shouldHighlightItemAt:)** (Bool) - Asks if the item should be highlighted. - **pagerView(_:didHighlightItemAt:)** (Void) - Tells the delegate the item was highlighted. - **pagerView(_:shouldSelectItemAt:)** (Bool) - Asks if the item should be selected. - **pagerView(_:didSelectItemAt:)** (Void) - Tells the delegate the item was selected. - **pagerView(_:willDisplay:forItemAt:)** (Void) - Tells the delegate the cell is about to be displayed. - **pagerView(_:didEndDisplaying:forItemAt:)** (Void) - Tells the delegate the cell was removed. - **pagerViewWillBeginDragging(_:)** (Void) - Tells the delegate scrolling is about to start. - **pagerViewWillEndDragging(_:targetIndex:)** (Void) - Tells the delegate scrolling has finished. - **pagerViewDidScroll(_:)** (Void) - Tells the delegate the content is scrolling. - **pagerViewDidEndScrollAnimation(_:)** (Void) - Tells the delegate scroll animation concluded. - **pagerViewDidEndDecelerating(_:)** (Void) - Tells the delegate deceleration has ended. ``` -------------------------------- ### FSPagerView Configuration Properties Source: https://context7.com/wenchaod/fspagerview/llms.txt Configure scrolling and bouncing behavior, and set a background view. `removesInfiniteLoopForSingleItem` prevents infinite looping with only one item. ```swift // Enable/disable scrolling pagerView.isScrollEnabled = true ``` ```swift // Enable/disable bouncing pagerView.bounces = true ``` ```swift // Always bounce horizontally pagerView.alwaysBounceHorizontal = true ``` ```swift // Always bounce vertically pagerView.alwaysBounceVertical = false ``` ```swift // Set background view let backgroundImageView = UIImageView(image: UIImage(named: "background")) pagerView.backgroundView = backgroundImageView ``` ```swift // Remove infinite loop when only one item exists pagerView.removesInfiniteLoopForSingleItem = true ``` -------------------------------- ### FSPagerView Configuration Properties Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md Configuration properties for controlling the behavior and layout of the FSPagerView component. ```APIDOC ## FSPagerView Configuration ### Description Properties used to configure the sliding behavior, item sizing, and spacing of the FSPagerView. ### Properties - **automaticSlidingInterval** (CGFloat) - The time interval of automatic sliding. 0 means disabling automatic sliding. Default is 0. - **isInfinite** (Bool) - A boolean value indicates whether the pager view has infinite number of items. Default is false. - **decelerationDistance** (UInt) - Determines the paging distance of the pager view. Default is 1. - **itemSize** (CGSize) - The item size of the pager view. Default is FSPagerViewAutomaticSize. - **interitemSpacing** (CGFloat) - The spacing to use between items in the pager view. Default is 0. ### Usage Example ```objc pagerView.automaticSlidingInterval = 3.0; pagerView.isInfinite = YES; pagerView.decelerationDistance = 2; pagerView.itemSize = CGSizeMake(200, 180); pagerView.interitemSpacing = 10; ``` ``` -------------------------------- ### Configure Infinite Scrolling Source: https://context7.com/wenchaod/fspagerview/llms.txt Enable or disable infinite scrolling for continuous user interaction. Optionally, prevent infinite loops when only a single item is present. ```swift // Enable infinite scrolling pagerView.isInfinite = true ``` ```swift // Disable infinite scrolling pagerView.isInfinite = false ``` ```swift // Remove infinite loop for single item (useful when dynamically loading content) pagerView.removesInfiniteLoopForSingleItem = true ``` -------------------------------- ### Set Image for Page Indicators Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Assign custom images for page indicators in their normal and selected states. ```swift pageControl.setImage(UIImage(named:"image1"), for: .normal) pageControl.setImage(UIImage(named:"image2"), for: .selected) ``` -------------------------------- ### Set Number of Pages for Page Control Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Configure the total number of page indicators displayed by the page control. Defaults to 0. ```swift pageControl.numberOfPages = 5 ``` -------------------------------- ### FSPagerView Transformers Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Configuration options for visual transformers to apply different transition effects to the pager view. ```APIDOC ## FSPagerView Transformers FSPagerView supports various built-in 3D transformers to enhance the visual experience. You can also create custom transformers by subclassing `FSPagerViewTransformer`. ### Available Transformers: * **Cross Fading** ```swift pagerView.transformer = FSPagerViewTransformer(type: .crossFading) ``` * **Zoom Out** ```swift pagerView.transformer = FSPagerViewTransformer(type: .zoomOut) ``` * **Depth** ```swift pagerView.transformer = FSPagerViewTransformer(type: .depth) ``` * **Linear** ```swift pagerView.transformer = FSPagerViewTransformer(type: .linear) ``` * **Overlap** ```swift pagerView.transformer = FSPagerViewTransformer(type: .overlap) ``` * **Ferris Wheel** ```swift pagerView.transformer = FSPagerViewTransformer(type: .ferrisWheel) ``` * **Inverted Ferris Wheel** ```swift pagerView.transformer = FSPagerViewTransformer(type: .invertedFerrisWheel) ``` * **Cover Flow** ```swift pagerView.transformer = FSPagerViewTransformer(type: .coverFlow) ``` * **Cubic** ```swift pagerView.transformer = FSPagerViewTransformer(type: .cubic) ``` ### Custom Transformers To create a custom transformer, subclass `FSPagerViewTransformer` and override the necessary methods. ``` -------------------------------- ### FSPagerViewDelegate: Did Highlight Item Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md This delegate method is called after an item has been highlighted. Use this to perform any actions or updates needed when an item receives a highlight state. ```objc - (void)pagerView:(FSPagerView *)pagerView didHighlightItemAtIndex:(NSInteger)index; ``` -------------------------------- ### Set Image for Page Control States Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md Sets a custom image for page indicators for specified states (normal and selected). ```objc [pageControl setImage:[UIImage imageNamed:@"image1"] forState:UIControlStateNormal]; [pageControl setImage:[UIImage imageNamed:@"image2"] forState:UIControlStateSelected]; ``` -------------------------------- ### Implement FSPagerViewDataSource: Cell for Item Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Dequeue and configure a cell for a specific index in the pager view. ```swift public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell { let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) cell.imageView?.image = ... cell.textLabel?.text = ... return cell } ``` -------------------------------- ### Set Path for Page Control States Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md Sets a custom UIBezierPath for page indicators for specified states (normal and selected). ```objc [pageControl setPath:[UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 8, 8)] forState:UIControlStateNormal]; [pageControl setPath: [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 8, 8)] forState:UIControlStateSelected]; ``` -------------------------------- ### Configure Item Size Source: https://context7.com/wenchaod/fspagerview/llms.txt Set the size of items within the pager view. Items can fill the entire view, have a fixed size, or scale based on the pager view's dimensions. ```swift // Fill entire pager view (default) pagerView.itemSize = FSPagerView.automaticSize ``` ```swift // Fixed size pagerView.itemSize = CGSize(width: 200, height: 180) ``` ```swift // Scale based on pager view size let transform = CGAffineTransform(scaleX: 0.8, y: 0.8) pagerView.itemSize = pagerView.frame.size.applying(transform) ``` ```swift // Different sizes for different transformers func configureForTransformer(type: FSPagerViewTransformerType) { switch type { case .crossFading, .zoomOut, .depth: pagerView.itemSize = FSPagerView.automaticSize case .linear, .overlap: let transform = CGAffineTransform(scaleX: 0.6, y: 0.75) pagerView.itemSize = pagerView.frame.size.applying(transform) case .ferrisWheel, .invertedFerrisWheel: pagerView.itemSize = CGSize(width: 180, height: 140) case .coverFlow: pagerView.itemSize = CGSize(width: 220, height: 170) case .cubic: let transform = CGAffineTransform(scaleX: 0.9, y: 0.9) pagerView.itemSize = pagerView.frame.size.applying(transform) } } ``` -------------------------------- ### FSPagerViewDelegate: Should Highlight Item Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md This delegate method allows you to control whether an item should be highlighted when the user interacts with it. Return YES to allow highlighting, NO otherwise. ```objc - (BOOL)pagerView:(FSPagerView *)pagerView shouldHighlightItemAtIndex:(NSInteger)index; ``` -------------------------------- ### Set Current Page for Page Control Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md Sets the currently active page indicator on the page control. Default is 0. ```objc pageControl.currentPage = 1; ``` -------------------------------- ### itemSize Property Source: https://context7.com/wenchaod/fspagerview/llms.txt Defines the size of each item within the pager view. ```APIDOC ## itemSize Property The item size of the pager view. When set to `FSPagerView.automaticSize`, items fill the entire visible area. Default is `FSPagerView.automaticSize`. ### Description This property allows you to specify the dimensions for each page item. You can use `FSPagerView.automaticSize` to make items fill the pager, set a fixed `CGSize`, or calculate a size based on transformations. ### Method Property Assignment ### Endpoint N/A (Client-side property) ### Parameters - **itemSize** (CGSize or `FSPagerView.automaticSize`) - The size of each item. ### Request Example ```swift // Fill entire pager view (default) pagerView.itemSize = FSPagerView.automaticSize // Fixed size pagerView.itemSize = CGSize(width: 200, height: 180) // Scale based on pager view size let transform = CGAffineTransform(scaleX: 0.8, y: 0.8) pagerView.itemSize = pagerView.frame.size.applying(transform) // Different sizes for different transformers func configureForTransformer(type: FSPagerViewTransformerType) { switch type { case .crossFading, .zoomOut, .depth: pagerView.itemSize = FSPagerView.automaticSize case .linear, .overlap: let transform = CGAffineTransform(scaleX: 0.6, y: 0.75) pagerView.itemSize = pagerView.frame.size.applying(transform) case .ferrisWheel, .invertedFerrisWheel: pagerView.itemSize = CGSize(width: 180, height: 140) case .coverFlow: pagerView.itemSize = CGSize(width: 220, height: 170) case .cubic: let transform = CGAffineTransform(scaleX: 0.9, y: 0.9) pagerView.itemSize = pagerView.frame.size.applying(transform) } } ``` ### Response N/A (Client-side property) ``` -------------------------------- ### Set item size Source: https://github.com/wenchaod/fspagerview/blob/master/README.md Configures the dimensions of items within the pager view. ```swift pagerView.itemSize = CGSize(width: 200, height: 180) ``` -------------------------------- ### Set Number of Pages for Page Control Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md Sets the total number of page indicators to be displayed on the page control. Default is 0. ```objc pageControl.numberOfPages = 5; ``` -------------------------------- ### FSPagerViewDelegate: Will Display Cell Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md This delegate method is invoked just before a cell is displayed for a given item index. It's useful for performing any last-minute cell configuration. ```objc - (void)pagerView:(FSPagerView *)pagerView willDisplayCell:(FSPagerViewCell *)cell forItemAtIndex:(NSInteger)index; ``` -------------------------------- ### Customize Transformer Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md Allows for custom transformer creation by subclassing FSPagerViewTransformer. ```objc > Customize your own transformer by subclassing`FSPagerViewTransformer.` ``` -------------------------------- ### FSPagerViewDelegate: Should Select Item Source: https://github.com/wenchaod/fspagerview/blob/master/README-OBJECTIVE-C.md This delegate method determines if an item should be selected. Return YES to allow selection, NO to prevent it. ```objc - (BOOL)pagerView:(FSPagerView *)pagerView shouldSelectItemAtIndex:(NSInteger)index; ```