测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可 | MIT |
发布上次发布 | 2017年11月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Xavier De Koninck 维护。
MultipleTabs 是一个自定义 iOS 组件,用于处理标签导航,类似于安卓的 Tabs 组件。它是完全用 Swift 开发的,但也可以在 ObjC 中使用。
https://material.io/guidelines/components/tabs.html
下载 MultipleTabs 并尝试使用包含的 iPhone/iPad 示例应用。
查看文档以全面了解 MultipleTabs 中所有可用功能。
MultipleTabs 不包含任何外部依赖项。
通过 Git 克隆源代码。
将 MultipleTabs 文件夹添加到您的项目(或工作空间)中。
导入框架
import MultipleTabs
创建一个新类并从 MultipleTabsViewController 继承
class ViewController: MultipleTabsViewController {
在 viewDidLoad 中注册您将用于每个标签的 collectionViewCells,并声明您的 dataSource MultipleTabsViewControllerDataSource
override func viewDidLoad() {
super.viewDidLoad()
register(type: Cell1.self, identifier: "Cell1")
register(type: Cell2.self, identifier: "Cell2")
dataSource = self
}
dataSource 应该实现 3 个回调方法
extension ViewController: MultipleTabsViewControllerDataSource {
/// The number of tabs you want
func numberOfTabs() -> Int {
return 2
}
/// The title for each tab
func title(forTabIndex index: Int) -> String {
return "Title"
}
/// Return the container cell you want for the tabIndex
func cell(forTabIndex index: Int) -> UICollectionViewCell {
let cell: UICollectionViewCell
if index == 0 {
cell = dequeue(identifier: "Cell1", index: index)
}
else {
cell = dequeue(identifier: "Cell2", index: index)
}
return cell
}
}
有一些可供定制的选项,但所有这些都具有默认值
/// The height for the titles bar
public var titlesHeight: CGFloat = 50
/// The color for the bottom selected border of the tab
public var titleBorderColor: UIColor = .black
/// The height for the bottom selected border of the tab
public var titleBorderHeight: CGFloat = 5
/// The color for the title label when selected
public var titleSelectedColor: UIColor = .black
/// The color for the title label when unselected
public var titleUnselectedColor: UIColor = .darkGray
/// The font for the title label when selected
public var titleSelectedFont: UIFont = .boldSystemFont(ofSize: 14)
/// The font for the title label when unselected
public var titleUnselectedFont: UIFont = .systemFont(ofSize: 14)
/// The multiplier for the size of the bottom selected border compared of the width of the tab title
public var borderWidthMultiplier: CGFloat = 0.8
有一些其他 dataSource 回调可用
/// Called just before cell will be displayed
@objc optional func willDisplay(cell: UICollectionViewCell, forTabIndex index: Int)
/// Called just after cell has been displayed
@objc optional func didEndDisplaying(cell: UICollectionViewCell, forTabIndex index: Int)
MultipleTabs 以开源的形式提供,不提供任何保证和找不到支持。但是,将尽力解决在 Github 上提出的任何问题。
如果您需要有关整合 MultipleTabs 或将其修改为满足您需求的帮助,请联系作者 Xavier De Koninck,寻求咨询机会。
MultipleTabs 版权归 © 2017 PagesJaunes SA 所有,并按照 MIT 许可证开源
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.