diff --git a/Demo/TabPageViewControllerDemo/ViewController.swift b/Demo/TabPageViewControllerDemo/ViewController.swift index c258134..3a38a28 100644 --- a/Demo/TabPageViewControllerDemo/ViewController.swift +++ b/Demo/TabPageViewControllerDemo/ViewController.swift @@ -55,5 +55,8 @@ class ViewController: UIViewController { option.tabMargin = 30.0 tc.option = option navigationController?.pushViewController(tc, animated: true) + + // Change tab title + tc.setTabItemTitle("Mon.(*)", at: 0) } } diff --git a/Sources/TabPageViewController.swift b/Sources/TabPageViewController.swift index 8d7ca25..7970801 100644 --- a/Sources/TabPageViewController.swift +++ b/Sources/TabPageViewController.swift @@ -29,7 +29,7 @@ open class TabPageViewController: UIPageViewController { return self.view.bounds.width } fileprivate var shouldScrollCurrentBar: Bool = true - lazy fileprivate var tabView: TabView = self.configuredTabView() + lazy open var tabView: TabView = self.configuredTabView() fileprivate var statusView: UIView? fileprivate var statusViewHeightConstraint: NSLayoutConstraint? fileprivate var tabBarTopConstraint: NSLayoutConstraint? @@ -313,6 +313,16 @@ extension TabPageViewController: UIPageViewControllerDataSource { public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { return nextViewController(viewController, isAfter: false) } + + public func setTabItemTitle(_ title: String, at: Int) { + guard 0.. Void)? var pageTabItems: [String] = [] { didSet { pageTabItemsCount = pageTabItems.count beforeIndex = pageTabItems.count + + // pageTabItems を変更したらリロード + if let c = collectionView { + print("Reload collectionView") + c.reloadData() + } } } var layouted: Bool = false @@ -117,7 +123,7 @@ internal class TabView: UIView { bottomBarViewHeightConstraint.constant = 1.0 / UIScreen.main.scale } - required internal init?(coder aDecoder: NSCoder) { + required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } } @@ -287,11 +293,11 @@ extension TabView { extension TabView: UICollectionViewDataSource { - internal func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return isInfinity ? pageTabItemsCount * 3 : pageTabItemsCount } - internal func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: TabCollectionCell.cellIdentifier(), for: indexPath) as! TabCollectionCell configureCell(cell, indexPath: indexPath) return cell @@ -325,7 +331,7 @@ extension TabView: UICollectionViewDataSource { } } - func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { + public func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { // FIXME: Tabs are not displayed when processing is performed during introduction display if let cell = cell as? TabCollectionCell, layouted { let fixedIndex = isInfinity ? indexPath.item % pageTabItemsCount : indexPath.item @@ -339,7 +345,7 @@ extension TabView: UICollectionViewDataSource { extension TabView: UICollectionViewDelegate { - internal func scrollViewDidScroll(_ scrollView: UIScrollView) { + public func scrollViewDidScroll(_ scrollView: UIScrollView) { if scrollView.isDragging { currentBarView.isHidden = true let indexPath = IndexPath(item: currentIndex, section: 0) @@ -362,7 +368,7 @@ extension TabView: UICollectionViewDelegate { } - internal func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) { + public func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) { // Accept the touch event because animation is complete updateCollectionViewUserInteractionEnabled(true) @@ -384,7 +390,7 @@ extension TabView: UICollectionViewDelegate { extension TabView: UICollectionViewDelegateFlowLayout { - internal func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { if let size = cachedCellSizes[indexPath] { return size @@ -398,11 +404,11 @@ extension TabView: UICollectionViewDelegateFlowLayout { return size } - func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { + public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { return 0.0 } - func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { + public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { return 0.0 } }