diff --git a/FSPageViewExample-Swift/FSPagerViewExample/BasicExampleViewController.swift b/FSPageViewExample-Swift/FSPagerViewExample/BasicExampleViewController.swift index 57c806b..92d340b 100644 --- a/FSPageViewExample-Swift/FSPagerViewExample/BasicExampleViewController.swift +++ b/FSPageViewExample-Swift/FSPagerViewExample/BasicExampleViewController.swift @@ -163,8 +163,8 @@ class BasicExampleViewController: UIViewController,UITableViewDataSource,UITable return self.numberOfItems } - public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell { - let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) + public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> UICollectionViewCell { + let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) as! FSPagerViewCell cell.imageView?.image = UIImage(named: self.imageNames[index]) cell.imageView?.contentMode = .scaleAspectFill cell.imageView?.clipsToBounds = true diff --git a/FSPageViewExample-Swift/FSPagerViewExample/PageControlExampleViewController.swift b/FSPageViewExample-Swift/FSPagerViewExample/PageControlExampleViewController.swift index 710aca7..03c6c1f 100644 --- a/FSPageViewExample-Swift/FSPagerViewExample/PageControlExampleViewController.swift +++ b/FSPageViewExample-Swift/FSPagerViewExample/PageControlExampleViewController.swift @@ -215,8 +215,8 @@ class PageControlExampleViewController: UIViewController,UITableViewDataSource,U return self.imageNames.count } - public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell { - let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) + public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> UICollectionViewCell { + let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) as! FSPagerViewCell cell.imageView?.image = UIImage(named: self.imageNames[index]) cell.imageView?.contentMode = .scaleAspectFill return cell diff --git a/FSPageViewExample-Swift/FSPagerViewExample/TransformerExampleViewController.swift b/FSPageViewExample-Swift/FSPagerViewExample/TransformerExampleViewController.swift index 4a66714..0818f26 100644 --- a/FSPageViewExample-Swift/FSPagerViewExample/TransformerExampleViewController.swift +++ b/FSPageViewExample-Swift/FSPagerViewExample/TransformerExampleViewController.swift @@ -99,8 +99,8 @@ class TransformerExampleViewController: UIViewController,FSPagerViewDataSource,F return imageNames.count } - public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell { - let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) + public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> UICollectionViewCell { + let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) as! FSPagerViewCell cell.imageView?.image = UIImage(named: self.imageNames[index]) cell.imageView?.contentMode = .scaleAspectFill cell.imageView?.clipsToBounds = true diff --git a/FSPagerViewExample-Objc/FSPagerViewExample-Objc/BasicExampleViewController.m b/FSPagerViewExample-Objc/FSPagerViewExample-Objc/BasicExampleViewController.m index fe05e72..80aff77 100644 --- a/FSPagerViewExample-Objc/FSPagerViewExample-Objc/BasicExampleViewController.m +++ b/FSPagerViewExample-Objc/FSPagerViewExample-Objc/BasicExampleViewController.m @@ -208,9 +208,9 @@ - (NSInteger)numberOfItemsInPagerView:(FSPagerView *)pagerView return self.numberOfItems; } -- (FSPagerViewCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index +- (UICollectionViewCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index { - FSPagerViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"cell" atIndex:index]; + FSPagerViewCell *cell = (FSPagerViewCell *)[pagerView dequeueReusableCellWithReuseIdentifier:@"cell" atIndex:index]; cell.imageView.image = [UIImage imageNamed:self.imageNames[index]]; cell.imageView.contentMode = UIViewContentModeScaleAspectFill; cell.imageView.clipsToBounds = YES; diff --git a/FSPagerViewExample-Objc/FSPagerViewExample-Objc/PageControlExampleViewController.m b/FSPagerViewExample-Objc/FSPagerViewExample-Objc/PageControlExampleViewController.m index 3c159bf..b3d9846 100644 --- a/FSPagerViewExample-Objc/FSPagerViewExample-Objc/PageControlExampleViewController.m +++ b/FSPagerViewExample-Objc/FSPagerViewExample-Objc/PageControlExampleViewController.m @@ -150,9 +150,9 @@ - (NSInteger)numberOfItemsInPagerView:(FSPagerView *)pagerView return self.imageNames.count; } -- (FSPagerViewCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index +- (UICollectionViewCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index { - FSPagerViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"cell" atIndex:index]; + FSPagerViewCell *cell = (FSPagerViewCell *)[pagerView dequeueReusableCellWithReuseIdentifier:@"cell" atIndex:index]; cell.imageView.contentMode = UIViewContentModeScaleAspectFill; cell.imageView.image = [UIImage imageNamed:self.imageNames[index]]; return cell; diff --git a/FSPagerViewExample-Objc/FSPagerViewExample-Objc/TransformerExampleViewController.m b/FSPagerViewExample-Objc/FSPagerViewExample-Objc/TransformerExampleViewController.m index 1681085..e4741e5 100644 --- a/FSPagerViewExample-Objc/FSPagerViewExample-Objc/TransformerExampleViewController.m +++ b/FSPagerViewExample-Objc/FSPagerViewExample-Objc/TransformerExampleViewController.m @@ -80,9 +80,9 @@ - (NSInteger)numberOfItemsInPagerView:(FSPagerView *)pagerView return self.imageNames.count; } -- (FSPagerViewCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index +- (UICollectionViewCell *)pagerView:(FSPagerView *)pagerView cellForItemAtIndex:(NSInteger)index { - FSPagerViewCell * cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"cell" atIndex:index]; + FSPagerViewCell * cell = (FSPagerViewCell *)[pagerView dequeueReusableCellWithReuseIdentifier:@"cell" atIndex:index]; cell.imageView.image = [UIImage imageNamed:self.imageNames[index]]; cell.imageView.contentMode = UIViewContentModeScaleAspectFill; cell.imageView.clipsToBounds = YES; diff --git a/README.md b/README.md index c3ff8ec..4785a24 100644 --- a/README.md +++ b/README.md @@ -309,8 +309,8 @@ public func numberOfItems(in pagerView: FSPagerView) -> Int { return numberOfItems } -public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell { - let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) +public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> UICollectionViewCell { + let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) as! FSPagerViewCell cell.imageView?.image = ... cell.textLabel?.text = ... return cell @@ -348,14 +348,14 @@ func pagerView(_ pagerView: FSPagerView, didSelectItemAt index: Int) --- ```swift -func pagerView(_ pagerView: FSPagerView, willDisplay cell: FSPagerViewCell, forItemAt index: Int) +func pagerView(_ pagerView: FSPagerView, willDisplay cell: UICollectionViewCell, forItemAt index: Int) ``` > Tells the delegate that the specified cell is about to be displayed in the pager view. --- ```swift -func pagerView(_ pagerView: FSPagerView, didEndDisplaying cell: FSPagerViewCell, forItemAt index: Int) +func pagerView(_ pagerView: FSPagerView, didEndDisplaying cell: UICollectionViewCell, forItemAt index: Int) ``` > Tells the delegate that the specified cell was removed from the pager view. diff --git a/Sources/FSPagerView.swift b/Sources/FSPagerView.swift index 7fb17d9..164c021 100644 --- a/Sources/FSPagerView.swift +++ b/Sources/FSPagerView.swift @@ -21,7 +21,7 @@ public protocol FSPagerViewDataSource: NSObjectProtocol { /// Asks your data source object for the cell that corresponds to the specified item in the pager view. @objc(pagerView:cellForItemAtIndex:) - func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell + func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> UICollectionViewCell } @@ -46,11 +46,11 @@ public protocol FSPagerViewDelegate: NSObjectProtocol { /// Tells the delegate that the specified cell is about to be displayed in the pager view. @objc(pagerView:willDisplayCell:forItemAtIndex:) - optional func pagerView(_ pagerView: FSPagerView, willDisplay cell: FSPagerViewCell, forItemAt index: Int) + optional func pagerView(_ pagerView: FSPagerView, willDisplay cell: UICollectionViewCell, forItemAt index: Int) /// Tells the delegate that the specified cell was removed from the pager view. @objc(pagerView:didEndDisplayingCell:forItemAtIndex:) - optional func pagerView(_ pagerView: FSPagerView, didEndDisplaying cell: FSPagerViewCell, forItemAt index: Int) + optional func pagerView(_ pagerView: FSPagerView, didEndDisplaying cell: UICollectionViewCell, forItemAt index: Int) /// Tells the delegate when the pager view is about to start scrolling the content. @objc(pagerViewWillBeginDragging:) @@ -379,7 +379,7 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega return } let index = indexPath.item % self.numberOfItems - function(self,cell as! FSPagerViewCell,index) + function(self,cell,index) } public func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { @@ -387,7 +387,7 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega return } let index = indexPath.item % self.numberOfItems - function(self,cell as! FSPagerViewCell,index) + function(self,cell,index) } public func scrollViewDidScroll(_ scrollView: UIScrollView) { @@ -451,7 +451,7 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega /// Register a nib file for use in creating new pager view cells. /// /// - Parameters: - /// - nib: The nib object containing the cell object. The nib file must contain only one top-level object and that object must be of the type FSPagerViewCell. + /// - nib: The nib object containing the cell object. The nib file must contain only one top-level object and that object must be of the type UICollectionViewCell. /// - identifier: The reuse identifier to associate with the specified nib file. This parameter must not be nil and must not be an empty string. @objc(registerNib:forCellWithReuseIdentifier:) open func register(_ nib: UINib?, forCellWithReuseIdentifier identifier: String) { @@ -463,15 +463,12 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega /// - Parameters: /// - identifier: The reuse identifier for the specified cell. This parameter must not be nil. /// - index: The index specifying the location of the cell. - /// - Returns: A valid FSPagerViewCell object. + /// - Returns: A valid UICollectionViewCell object. @objc(dequeueReusableCellWithReuseIdentifier:atIndex:) - open func dequeueReusableCell(withReuseIdentifier identifier: String, at index: Int) -> FSPagerViewCell { + open func dequeueReusableCell(withReuseIdentifier identifier: String, at index: Int) -> UICollectionViewCell { let indexPath = IndexPath(item: index, section: self.dequeingSection) let cell = self.collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) - guard cell.isKind(of: FSPagerViewCell.self) else { - fatalError("Cell class must be subclass of FSPagerViewCell") - } - return cell as! FSPagerViewCell + return cell } /// Reloads all of the data for the collection view. @@ -532,7 +529,7 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega /// - Parameter cell: The cell object whose index you want. /// - Returns: The index of the cell or NSNotFound if the specified cell is not in the pager view. @objc(indexForCell:) - open func index(for cell: FSPagerViewCell) -> Int { + open func index(for cell: UICollectionViewCell) -> Int { guard let indexPath = self.collectionView.indexPath(for: cell) else { return NSNotFound } @@ -544,9 +541,9 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega /// - Parameter index: The index that specifies the position of the cell. /// - Returns: The cell object at the corresponding position or nil if the cell is not visible or index is out of range. @objc(cellForItemAtIndex:) - open func cellForItem(at index: Int) -> FSPagerViewCell? { + open func cellForItem(at index: Int) -> UICollectionViewCell? { let indexPath = self.nearbyIndexPath(for: index) - return self.collectionView.cellForItem(at: indexPath) as? FSPagerViewCell + return self.collectionView.cellForItem(at: indexPath) } // MARK: - Private functions