william-weng/wwcapsuletabbarcontroller
- Based on UITabBarController, implement a TabBarController that can display more than six Tabs.
[Introduction - 簡介](https://swiftpackageindex.com/William-Weng)
- Based on UITabBarController, implement a TabBarController that can display more than six Tabs.
- 基於UITabBarController,實現能顯示六個以上Tab的TabBarController。
https://github.com/user-attachments/assets/0f5450ef-987e-4484-8a5b-2795a55b518d
Installation with Swift Package Manager
dependencies: [
.package(url: "https://github.com/William-Weng/WWCapsuleTabBarController.git", .upToNextMajor(from: "1.3.1"))
]WWCapsuleTabBarControllerDelegate
|函式|功能| |-|-| |didSelectedTab(:withIndex:)|選到的分頁Tab的index| |backgroundSetting(:withIndex:)|選到的分頁Tab的整體背景相關設定| |itemSetting(:withIndex:)|分頁Item的相關設定| |itemTitleSetting(:withIndex:)|分頁Item文字相關設定|
Function - 可用函式
|函式|功能| |-|-| |initTabBarItemSetting(gapConstraint:)|初始化設定| |myDelegateSetting(:useAnimation:)|設定WWCapsuleTabBarControllerDelegate| |configure(withIndex:)|顏色 / 文字設定 for selectedIndex| |hidden(:duration:)|隱藏 / 顯示自訂TabBar|
Setting - 相關設定
- The homepage should inherit WWCapsuleTabBarController.
- 首頁要繼承WWCapsuleTabBarController。
Example - 範例
import UIKit
import WWCapsuleTabBarController
final class MyTabBarController: WWCapsuleTabBarController {
override func viewDidLoad() {
super.viewDidLoad()
initSetting()
}
}
// MARK: - WWCapsuleTabBarControllerDelegate
extension MyTabBarController: WWCapsuleTabBarControllerDelegate {
func didSelectedTab(_ tabBarController: WWCapsuleTabBarController, withIndex index: Int) {
print(index)
}
func backgroundSetting(_ tabBarController: WWCapsuleTabBarController, withIndex index: Int) -> WWCapsuleTabBarController.TabBarBackground? {
let settings: [WWCapsuleTabBarController.TabBarBackground] = [
(image: UIImage(named: "Green"), color: .black.withAlphaComponent(0.3), alpha: 1.0),
(image: UIImage(named: "Yellow"), color: .systemPink, alpha: 0.8),
(image: UIImage(named: "Blue"), color: .gray.withAlphaComponent(0.7), alpha: 0.6),
(image: UIImage(named: "Green"), color: .blue.withAlphaComponent(0.1), alpha: 0.4),
(image: UIImage(named: "Yellow"), color: .magenta.withAlphaComponent(0.5), alpha: 0.2),
(image: UIImage(named: "Blue"), color: .black.withAlphaComponent(0.8), alpha: 0.0),
]
return settings[safe: index]
}
func itemSetting(_ tabBarController: WWCapsuleTabBarController, withIndex index: Int) -> WWCapsuleTabBarController.TabBarItem? {
let settings: [WWCapsuleTabBarController.TabBarItem] = [
(icon: (normal: UIImage(systemName: "square.and.arrow.up"), selected: nil), color: (normal: .clear, selected: .red)),
(icon: (normal: UIImage(systemName: "folder.fill"), selected: nil), color: (normal: .clear, selected: .blue)),
(icon: (normal: UIImage(systemName: "book.fill"), selected: nil), color: (normal: .clear, selected: .brown)),
(icon: (normal: UIImage(systemName: "pencil.circle"), selected: UIImage(systemName: "pencil.circle.fill")), color: (normal: .darkGray, selected: .systemPink)),
(icon: (normal: UIImage(systemName: "folder.badge.person.crop"), selected: UIImage(systemName: "folder.fill.badge.person.crop")), color: (normal: .systemGreen, selected: .blue)),
(icon: (normal: UIImage(systemName: "trash"), selected: UIImage(systemName: "trash.fill")), color: (normal: .clear, selected: .magenta)),
]
return settings[safe: index]
}
func itemTitleSetting(_ tabBarController: WWCapsuleTabBarController, withIndex index: Int) -> WWCapsuleTabBarController.TabBarTitle? {
let settings: [WWCapsuleTabBarController.TabBarTitle] = [
(text: (normal: nil, selected: "主頁"), font: (normal: .systemFont(ofSize: 16, weight: .black), selected: nil), color: (normal: .clear, selected: .white)),
(text: (normal: nil, selected: "分類"), font: (normal: .systemFont(ofSize: 20, weight: .black), selected: nil), color: (normal: .clear, selected: .white)),
(text: (normal: "", selected: "項目"), font: (normal: nil, selected: .boldSystemFont(ofSize: 16)), color: (normal: .clear, selected: .white)),
(text: (normal: "", selected: "資訊"), font: (normal: nil, selected: .boldSystemFont(ofSize: 16)), color: (normal: .white, selected: .green)),
(text: (normal: "Setting", selected: "設定"), font: (normal: .italicSystemFont(ofSize: 12), selected: .boldSystemFont(ofSize: 16)), color: (normal: .white, selected: .magenta)),
(text: (normal: "My", selected: "我的"), font: (normal: .italicSystemFont(ofSize: 12), selected: .boldSystemFont(ofSize: 16)), color: (normal: .white, selected: .yellow)),
]
return settings[safe: index]
}
}
private extension MyTabBarController {
func initSetting() {
self.initTabBarItemSetting(gapConstraint: 16)
self.myDelegateSetting(self)
}
}import UIKit
import WWCapsuleTabBarController
final class Tab6ViewController: WWTabBarRootViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
}Package Metadata
Repository: william-weng/wwcapsuletabbarcontroller
Default branch: main
README: README.md