To run the example project, clone the repo, and run pod install
from the Example directory first.
//1.引入库
import HaidoraStatusProvider
//2.对需要使用hud的对象实现HaidoraStatusable
class ViewController: UIViewController,HaidoraStatusable {
override func viewDidLoad() {
super.viewDidLoad()
//设置默认的provider(全局设置一次即可)
HaidoraStatusConfig.shareInstance.provider = MBProgressHUDSwiftWrap.self
}
@IBAction func showAction(sender: AnyObject) {
//显示
self.show()
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(3 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
//隐藏
self.hide()
}
}
}
当HaidoraStatusable提供的默认方法不够用时,可针对该协议扩展
extension HaidoraStatusable {
public func custom_method() {
print("上层接口-自定义方法")
let statusView = self.buildProvider()
//事件转发到Provider
statusView.custom_method()
}
}
extension HaidoraStatusProvider {
public func custom_method() {
print("真正实现-自定义方法")
}
}
extension HaidoraStatusProvider where Self: MBProgressHUDSwiftWrap {
public func custom_method() {
print("某种hud-自定义方法")
}
}
- Xcode8+
- Swift3.0
- iOS8+
HaidoraStatusProvider is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "HaidoraStatusProvider"
mrdaios, mrdaios@gmail.com
HaidoraStatusProvider is available under the MIT license. See the LICENSE file for more info.