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

Add setTabItemTitle #59

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Demo/TabPageViewControllerDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
12 changes: 11 additions & 1 deletion Sources/TabPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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..<tabItems.count ~= at else {
print("Specified `at` argument was out of range")
return
}

tabItems[at].title = title
tabView.pageTabItems[at] = tabItems[at].title
}
}


Expand Down
26 changes: 16 additions & 10 deletions Sources/TabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@

import UIKit

internal class TabView: UIView {
open class TabView: UIView {

var pageItemPressedBlock: ((_ index: Int, _ direction: UIPageViewControllerNavigationDirection) -> 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
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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
}
}