Swift3.0 MBProgressHUD的封装使用
来源:互联网 发布:java 计算圆周率 编辑:程序博客网 时间:2024/06/06 03:24
创建 UIViewController+HUD.swift
import Foundationimport MBProgressHUD// keyWindowlet KeyWindow : UIWindow = UIApplication.shared.keyWindow!private var HUDKey = "HUDKey"extension UIViewController{ var hud : MBProgressHUD? { get{ return objc_getAssociatedObject(self, &HUDKey) as? MBProgressHUD } set{ objc_setAssociatedObject(self, &HUDKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) } } /** 显示提示信息(有菊花, 一直显示, 不消失),默认文字“加载中”,默认偏移量0 - parameter view: 显示在哪个View上 - parameter hint: 提示信息 - parameter yOffset: y上的偏移量 */ func showHud(in view: UIView, hint: String = "加载中...", yOffset:CGFloat? = 0){ let HUD = MBProgressHUD(view: view) HUD.label.text = hint HUD.label.font = UIFontSize(size: 15*UIRate) //设为false后点击屏幕其他地方有反应 HUD.isUserInteractionEnabled = true //HUD内的内容的颜色 HUD.contentColor = UIColor(red:0.82, green:0.82, blue:0.82, alpha:1.00) //View的颜色 HUD.bezelView.color = UIColorHex("000000", 0.7) //style -blur 不透明 -solidColor 透明 HUD.bezelView.style = .solidColor HUD.margin = 12*UIRate //偏移量,以center为起点// HUD.offset.y = yOffset ?? 0 view.addSubview(HUD) HUD.show(animated: true) hud = HUD } /** 显示纯文字提示信息(显示在keywindow上),默认时间2s,默认偏移量0 - parameter hint: 提示信息 - parameter duration: 持续时间(不填的话, 默认两秒) - parameter yOffset: y上的偏移量 */ func showHintInKeywindow(hint: String, duration: Double = 2.0, yOffset:CGFloat? = 0) { let view = KeyWindow let HUD = MBProgressHUD(view: view) view.addSubview(HUD) HUD.animationType = .zoomOut HUD.isUserInteractionEnabled = false HUD.bezelView.color = UIColor.black HUD.contentColor = UIColor.white HUD.mode = .text HUD.label.text = hint HUD.show(animated: true) HUD.removeFromSuperViewOnHide = false HUD.offset.y = yOffset ?? 0 HUD.margin = 12*UIRate HUD.hide(animated: true, afterDelay: duration) hud = HUD } /** 显示纯文字提示信息,默认时间1.5s,默认偏移量0 - parameter view: 显示在哪个View上 - parameter hint: 提示信息 - parameter duration: 持续时间(不填的话, 默认两秒) - parameter yOffset: y上的偏移量 */ func showHint(in view: UIView, hint: String, duration: Double = 1.5, yOffset:CGFloat? = 0) { let HUD = MBProgressHUD(view: view) view.addSubview(HUD) HUD.animationType = .zoomOut HUD.bezelView.color = UIColor.black HUD.contentColor = UIColor.white HUD.mode = .text HUD.label.text = hint HUD.isUserInteractionEnabled = false HUD.removeFromSuperViewOnHide = false HUD.show(animated: true) HUD.offset.y = yOffset ?? 0 HUD.margin = 12*UIRate HUD.hide(animated: true, afterDelay: duration) hud = HUD } /// 移除提示 func hideHud() { //如果解包成功则移除,否则不做任何事 if let hud = hud { hud.hide(animated: true) } } }
首先导入MBProgressHUD,然后进行封装,在使用时,在UIViewController 中
//添加HUD self.showHud(in: self.view, hint: "加载中...")//隐藏HUDself.hideHud()
0 0
- Swift3.0 MBProgressHUD的封装使用
- MBProgressHUD的简单封装
- 基于MBProgressHUD的封装
- MBProgressHUD的简单封装
- swift3.0 coredata 的使用
- Swift3.0 popToViewController 的使用
- Swift3.0 popToViewController 的使用
- swift3.0:sqlite3的使用
- MBProgressHUD的使用
- MBProgressHUD的使用
- MBProgressHUD的基本使用
- MBProgressHUD的使用
- iOS MBProgressHUD的使用
- MBProgressHUD的使用
- MBProgressHUD的使用-ios
- MBProgressHUD的基本使用
- MBProgressHUD框架的使用
- MBProgressHUD 的使用详解
- bind()方法实现input绑定回车查询
- mysql explain亲测
- Linux 定时ftp下载
- 整合的图片压缩工具类ImageTools
- 资源
- Swift3.0 MBProgressHUD的封装使用
- python中的set
- 在 Android 中主线程如何给子线程发 Message?
- OpenStack网络指南(25)路由提供商网络
- 第一个 Spring Boot 程序 : 文件上传
- HTML基本属性
- select与datalist在制作下拉菜单时的区别
- Android源码树添加新的APP(含第三方so、jar)
- Java程序员到架构师的推荐阅读书籍