RBHUD 0.1.0

RBHUD 0.1.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2015 年 9 月
SPM支持 SPM

Robert Bojor 维护。



RBHUD 0.1.0

RBHUD

使用 Swift 编写的 HUD - 即刻可用,无需麻烦…

RBHUD written in Swift

如何安装

手动安装

下载存档仓库,将其解压缩到您的驱动器上的某个位置,然后只需将 RBHUD.swift 文件拖放到您的项目中即可开始使用 - 就这么简单!

在您的项目中使用它

  • 在您的 ViewController 中声明一个变量
let hud = RBHUD.sharedInstance
  • 使用 15 个可用选项之一配置 HUD。省略任何配置变量都将使 HUD 加载默认设置(下面看到的实际值)
self.hud.backdropOpacity = 0.8    // The opacity of the background
self.hud.backdropUsesBlur = true    // Option for the background if it should use a blur effect or not
self.hud.backdropBlurStyle = UIBlurEffectStyle.Dark   // The blur style, if it's using a blue effect
self.hud.backdropColor = UIColor(red:0.23, green:0.26, blue:0.29, alpha:1)    // The background color of the overlay, if not using a blur effect

self.hud.progressViewLineWidth = 1.0    // The progress indicator line width
self.hud.progressViewSize = 64.0   // The progress indicator's size on the screen
self.hud.progressViewPadding = 10.0   // The top and bottom padding between the progress indicator and any other elements on the screen
self.hud.progressViewStrokeColor = UIColor.whiteColor()   // The color of the progress view stroke line
self.hud.progressViewFillColor = UIColor.clearColor()   // The fill color of the progress view

self.hud.successViewLineWidth = 1.0     // The line width for the success mark
self.hud.successViewStrokeColor = UIColor.greenColor()      // The line color for the success mark

self.hud.errorViewLineWidth = 1.0       // The line width for the error mark
self.hud.errorViewStrokeColor = UIColor.redColor()      // The line color for the error mark


self.hud.labelAnimationDistance = 50.0    // The distance the text labels have to travel when appearing
self.hud.labelFontName = "HelveticaNeue-Light"    // The font name for the text labels
self.hud.labelTitleFontSize = 20.0    // The font size for the title label
self.hud.labelTitleTextColor = UIColor.whiteColor()   // The text color of the title label

self.hud.labelSubtitleFontSize = 13.0   // The font size for the subtitle label
self.hud.labelSubtitleTextColor = UIColor.whiteColor()    // The text color for the subtitle label
  • 调用显示方法
self.hud.showLoader(inView:UIView!, withTitle:String?, withSubTitle:String?, withProgress:Bool)

showLoader 方法有 4 个参数,其中 2 个是可选的

  • inView:UIView 是您要在其中显示 HUD 的视图,通常是 self.view
  • withTitle:String? 是在加载时显示的标题文本字符串。当发送此为 nil 时,HUD 不会显示标题文本
  • withSubTitle:String? 是在加载时显示的副标题文本字符串。当发送此为 nil 时,HUD 不会显示副标题文本
  • withProgress:Bool 如果您希望 HUD 显示不可确定进度指示器,请将其设置为 true,否则设置为 false

如果您的代码中的任何步骤都需要更新 HUD 的外观,例如更改标题文本并添加进度指示器,您可以通过使用新参数再次调用带有新参数的 showLoader 方法来实现,而 HUD 将在保持显示的同时更新新数据。

  • 使用成功标志调用显示
self.hud.showWithSuccess(self.view, withTitle: "Success", withSubTitle: "The task ended up successfully!")

showWithSuccess 方法有 3 个参数,其中 2 个是可选的

  • inView:UIView 是您要在其中显示 HUD 的视图,通常是 self.view
  • withTitle:String? 是在加载时显示的标题文本字符串。当发送此为 nil 时,HUD 不会显示标题文本
  • withSubTitle:String? 是在加载时显示的副标题文本字符串。当发送此为 nil 时,HUD 不会显示副标题文本

  • 使用错误标志调用显示

self.hud.showWithError(self.view, withTitle: "Oops", withSubTitle: "En error occured!")

showWithError 方法有 3 个参数,其中 2 个是可选的

  • inView:UIView 是您要在其中显示 HUD 的视图,通常是 self.view
  • withTitle:String? 是在加载时显示的标题文本字符串。当发送此为 nil 时,HUD 不会显示标题文本
  • withSubTitle:String? 是在加载时显示的副标题文本字符串。当发送此为 nil 时,HUD 不会显示副标题文本

showWithErrorshowWithSuccess 方法将在几秒钟后关闭 HUD,因此无需调用隐藏方法。

  • 在您完成长时间操作后,调用隐藏方法
self.hud.hideLoader()

使用示例

使用 HUD 的标准方式将类似于以下代码…

self.hud.showLoader(self.view, withTitle:"Testing", withSubTitle:nil, withProgress:true)
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
    // Your longer task code goes here...
    dispatch_async(dispatch_get_main_queue(), { () -> Void in
        self.hud.hideLoader()
    })
})

如果您的代码中的任何步骤需要更新HUD的外观,例如比如更改标题文本并添加进度指示器,您可以通过再次调用带有新参数的 showLoader 方法来实现,同时HUD将使用新数据更新自身,而仍然保持显示。例如

func someMethod()
{
    self.hud.showLoader(self.view, withTitle:"Testing", withSubTitle:nil, withProgress:true)
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
        // Your longer task code goes here...
        if self.thisVar == 0 {
            self.hud.showLoader(self.view, withTitle:"New title", withSubTitle:"and subtitle", withProgress:false)
            self.someOtherMethod()
        }
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            self.hud.hideLoader()
        })
    })
}

func someOtherMethod()
{
    // Your logic here...
    dispatch_async(dispatch_get_main_queue(), { () -> Void in
        self.hud.hideLoader()
    })
}

附在仓库中的Xcode项目也包含调用和隐藏HUD的示例。

待办事项

  • 为覆盖层添加部分覆盖屏幕的选项,包括圆角。

作者

Robert Bojor,[email protected]

许可

RBHUD在MIT许可下可用。有关更多信息,请参阅LICENSE文件。