🍫
Energy BarEnergy Bar 是一个非常简单的消息栏,用以获取用户的反馈。
安装
pod 'EnergyBar'
使用方法
初始化
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let energyBar = EnergyBar(delegate: self)
return true
}
}
extension AppDelegate: EnergyBarDelegate {
func buttonTap(eventID: String, tag: Int) {
//handle your event
}
}
显示 EnergyBar
try? energyBar.show(eventID:messageLabel:buttons:size:)
将顶级窗口带到前面
energyBar.bringEnergyBarToFront()
更好的使用方法
- 将
energyBar
创建为单例,如App.energyBar
AppDelegate
类必须具备EnergyBarDelegate
- 让自定义事件使用
enum
类似...
和...enum EnergyBarEvents: String { case doSomething = "doSomethingEvent" }
然后将枚举的原始值传递到eventID: EnergyBarEvents.doSomething.rawValue
show
方法,例如...if let event = EnergyBarEvents(rawValue: eventID) { switch event { case .doSomething: //handle event } }