FillTheTank
一个可自定义的容器视图,支持填充动画。
安装
要使用 CocoaPods 安装 FillTheTank,请将以下内容包含在您的 Podfile 中
pod 'FillTheTank'
如何做
首先,导入 FillTheTank 模块
import FillTheTank
然后首先创建一个 LevelManager 来确定一些基本变量。
-
directions: bottomUp
⬆️ , topDown⬇️ , leftToRight➡️ , rightToLeft⬅️ -
countDownDuration: 级别移动动画持续时间
-
level: 0~1 之间的数值,0: 空和 1: 满满的
-
fillingsColor: 容器填充颜色
let manager = LevelManager(moveWithDirection: .leftToRight, duration: 2.0, initLevel: 0.0, fillingsColor: .orange)
现在我们可以使用 FillUpManager 对象创建我们的 Tank 视图并进行一些 UI 自定义
// Title label text attributes
let textAttributes = [
NSAttributedString.Key.foregroundColor: UIColor.white,
NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 20)]
// Initial tank view with LevelManager
let tank = Tank(lvManager: manager)
.cornerRadius(10.0)
.borderColor(.orange)
.borderWidth(3.0)
.backgroundColor(.white)
.dismissWhenTankIsFull(true)
.titleLabel(attributedString: "pod \"FillTheTank\"",
withAttributes: textAttributes)
// Add tank into view hierarchy
view.addSubView(tank)
// Set up constraints
NSLayoutConstraint.activate([tank.centerXAnchor.constraint(equalTo: view.centerXAnchor),
tank.centerYAnchor.constraint(equalTo: view.centerYAnchor),
tank.widthAnchor.constraint(equalTo:view.widthAnchor),
tank.heightAnchor.constraint(equalTo: view.heightAnchor)])
让我们把油罐填满
// If dismissWhenThankIsFill is set to TRUE and no custom completion block defined,
// tank view will be removed from superview when animation completed
tank.fillUptheTank()
或者您也可以定义自己的完成块(通过定义自定义完成块,您需要在需要时手动从父视图中移除油罐视图)
tank.fillUptheTank { (_) in
print("Tank is full!")
// Call dismiss() function to remove from superview
tank.dismiss()
}
通过更新下一个级别比率也可以更改油罐级别
tank.update(level: 0.8)
致谢
FillTheTank 由 Richard Lu([email protected])拥有和维护
许可证
MIT 许可证
版权所有 (c) 2019 richlu1018
以下为授权条款:任何人获得此软件及其相关文档副本(“软件”),均允许在此软件上无限制地进行操作,包括但不限于使用、复制、修改、合并、发布、分发、许可和/或销售软件的副本,并允许将软件提供给他人的权利,前提是必须遵守下述条件
上述版权声明和本授权声明应包含在所有软件副本或主要的部分。
该软件按“现状”提供,不提供任何形式的明示或暗示的保证,包括但不限于适用性、特定目的的适用性和非侵权性保证。在任何事件中,作者或版权所有者均不对任何主张、损害赔偿或其他责任承担任何责任,无论该责任是基于合同、侵权或其他原因,也不论该责任是出于软件或软件的使用或其他方式。