ExpandedTabBar v3.0.1
ExpandedTabBar 是针对 UITabBarController 中“更多”项的一种创新解决方案。它提供了更舒适和直观的用户体验。
- 要求
- 安装指南
- Cocoapods
- Swift包管理器
- 流程设置
- 带有Storyboard
- 程序化
- 代理
- 自定义
- 更多标签
- 支持浅色/深色模式
- 选项自定义
- 动画类型
- 指示器类型
- 示例
- 支持
- 告诉我们!
- 许可
要求
- iOS 11.0 +
- Swift 5.﹡
- XCode 10 +
安装
ExpandedTabBar 不包含任何外部依赖。
当前支持的安装选项如下
CocoaPods
要使用CocoaPods将ExpandedTabBar集成到Xcode项目中,请在您的Podfile中指定它
use_frameworks!
target '<Your Target Name>' do
pod 'ExpandedTabBar'
end
Swift Package Manager
Swift Package Manager 是一个用于自动分发 Swift 代码的工具,并将其集成到 swift 编译器中。它处于早期开发阶段,但 appstore-card-transition 支持在支持平台上使用。
一旦你设置了 Swift 包,将 ExpandedTabBar 添加为依赖项就像将其添加到 Package.swift
的 dependencies
值一样简单。
dependencies: [
.package(url: "https://github.com/yervandsar/ExpandedTabBar", from: "3.0.0")
]
或者你可以查看 通过 Apple 添加 App 的包依赖项
设置流程
-
使用 Storyboard
- 创建
UITabBarController
- 从
ExpandedTabBarController
延展 - 在 Storyboard 中设置为
UITabBarController
-
通过代码
let viewControllers: [UIViewController] = [...] // Array of view controllers for UITabBarController
let expandedTabBar = ExpandedTabBarController()
expandedTabBar.setup(viewControllers: viewControllers)
注意: viewControllers
数组中的任何 UIViewController
都必须具有 tabBarItem
。
代理
为了实现标签选择动作,实现 ExpandedTabBarControllerDelegate
func expandedTabBarController(
_ tabBarController: UITabBarController,
didSelect viewController: UIViewController,
withItem tabBarItem: UITabBarItem?
)
自定义
-
更多标签页
您可以在故事板中自定义更多标签页,或者以编程方式设置。
moreTitle : String // Default "More"
moreIcon : UIImage? // Default Image from SystemItem.More
moreSelectedIcon : UIImage? // Default nil
-
深色模式支持
ExpandedTabBar 完全支持 亮/暗 模式,并且您可以设置任何 UIColor
或 CGColor
。
let color: UIColor/CGColor = .pattern(light: UIColor, dark: UIColor)
注意:如果设备操作系统版本不支持深色模式,则默认为亮色。
-
选项自定义
ExpandedTabBar 的选项遵循 Options 协议。
public protocol Options {
var background : BackgroundOptions
var container : ContainerOptions
var animationType: AnimationType
var indicatorType: IndicatorTypes
}
背景选项
public protocol BackgroundOptions {
var color : UIColor // Default .clear
var alpha : CGFloat // Default 0.3
var closeOnTap: Bool // Default true
}
容器选项
public protocol ContainerOptions {
var color : UIColor // Default .pattern(light: .white, dark: .black)
var alpha : CGFloat // Default 1.0
var cornerRadius : CGFloat // Default 10
var roundedCorners: UIRectCorner // Default .allCorners
var bottomMargin : CGFloat // Default 15
var tabSpace : CGFloat // Default 8
var tab : ContainerTabOptions
var shadow : ShadowOptions? // Default nil
}
注意:对于阴影,您可以看到并使用 ShadowDefaultOptions
类。
容器的选项卡
public protocol ContainerTabOptions {
var itemHeight : CGFloat. // Default 35
var titleFont : UIFont // Default .systemFont(ofSize: 16)
var titleColor : UIColor // Default .pattern(light: .black, dark: .white)
var iconColor : UIColor // Default .pattern(light: .black, dark: .white)
var iconContentMode: UIView.ContentMode // Default .scaleAspectFit
var iconTitleSpace : CGFloat // Default 8
}
动画类型
无动画 | 翻译 | 缩放 | 旋转 |
---|---|---|---|
.none |
.top 默认 |
.zoomIn |
.rotatePositive |
![]() |
![]() |
![]() |
![]() |
.crossDissolve |
.bottom |
.zoomOut |
.rotateNegative |
![]() |
![]() |
![]() |
![]() |
.left |
.zoomX |
.rotate(angle: .pi/6) |
|
![]() |
![]() |
![]() |
|
.right |
.zoomY |
||
![]() |
![]() |
注意: 你可以创建自己的动画 .custom(AnimationProtocol)
。你可以使用 TransformAnimation 来创建自定义动画
指示器类型
.none |
.connectedLine |
.triangle 默认 |
---|---|---|
![]() |
![]() |
![]() |
示例
final class CustomViewController: ExpandedTabBarController {
override func viewDidLoad() {
super.viewDidLoad()
expandedDelegate = self
expandedTabBarOptions = customOptions
}
private var customOptions: Options {
var options = ExpandedTabBarOptions()
options.indicatorType = .connectedLine
options.animationType = .custom(customAnimation)
options.container.roundedCorners = [.topLeft, .topRight, .bottomLeft]
options.container.cornerRadius = 20
options.container.shadow = ShadowDefaultOptions()
options.container.tabSpace = 15
options.container.tab.iconTitleSpace = 15
return options
}
private var customAnimation: AnimationProtocol {
let transform = CGAffineTransform(scaleX: 0.1, y: 0.1).rotated(by: .pi)
return TransformAnimation(transform: transform)
}
}
extension CustomViewController: ExpandedTabBarControllerDelegate {
func expandedTabBarController(_ tabBarController: UITabBarController,
didSelect viewController: UIViewController,
withItem tabBarItem: UITabBarItem?) {
// Do some logic here
}
}
支持
自由地 提出问题,包括任何建议、错误报告、功能请求或问题。
告诉我们!
如果您愿意,可以将使用我们组件的项目链接发送给我们。只需通过电子邮件发送到 [email protected],并告知我们是否有任何关于动画的问题或建议。
许可证
MIT 许可证 (MIT)
版权所有 (c) 2018 Yervand Saribekyan
此处特此许可任何人,无需支付任何费用,获取本软件及其相关文档文件(“软件”),无限制地使用软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本来供软件接收人使用,前提是必须遵守以下条件
必须在所有软件副本或重要部分中包括上述版权声明和本许可声明。
软件按“现状”提供,不包括任何明示或默示的保证,包括但不限于适销性、针对特定目的的适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论是基于合同、侵权或其他任何方式,该索赔、损害或其他责任源于、产生于或与本软件或其使用或其他操作有关。