GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - abanca/HKProgressHUD: Swift MBProgressHUD

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

89 Commits
89 Commits

Folders and files

NameName
Last commit message
Last commit date
HKProgressHUD.xcodeproj
HKProgressHUD.xcodeproj
 
 
HKProgressHUD.xcworkspace
HKProgressHUD.xcworkspace
 
 
HudDemo
HudDemo
 
 
ProgressHUD
ProgressHUD
 
 
bin
bin
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
Cartfile.private
Cartfile.private
 
 
Cartfile.resolved
Cartfile.resolved
 
 
HKProgressHUD.podspec
HKProgressHUD.podspec
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

HKProgressHUD

Build Status codecov CocoaPod Platform CocoaPods compatible Carthage compatible License: MIT

HKProgressHUD is an iOS drop-in class in pure-Swift that displays a translucent HUD with an indicator and/or labels while work is being done in a background thread. The HUD is meant as a replacement for the undocumented, private UIKit UIProgressHUD with some additional features.This project is heavily inspired by the popular MBProgressHUD.

Requirements

HKProgressHUD works on iOS 8+. You will need the latest developer tools in order to build HKProgressHUD. Old Xcode versions might work, but compatibility will not be explicitly maintained.

Adding HKProgressHUD to your project

CocoaPods

CocoaPods is the recommended way to add HKProgressHUD to your project.

  1. Add a pod entry for HKProgressHUD to your Podfile pod 'HKProgressHUD', '~> 0.8.0'
  2. Update the pod(s) by running pod update.

Carthage

  1. Add HKProgressHUD to your Cartfile. e.g., github "huaweikang/HKProgressHUD" ~> 0.8.0
  2. Run carthage update
  3. Follow the rest of the standard Carthage installation instructions to add HKProgressHUD to your project.

Source files

Alternatively you can directly add the HKProgressHUD.swift and ProgressView.swift source files to your project.

Usage

The main guideline you need to follow when dealing with HKProgressHUD while running long-running tasks is keeping the main thread work-free, so the UI can be updated promptly. The recommended way of using HKProgressHUD is therefore to set it up on the main thread and then spinning the task, that you want to perform, off onto a new thread.

let hud = HKProgressHUD.show(addedToView: self.view, animated: true)
DispatchQueue.global(qos: .userInitiated).async {
    // Do something...
    DispatchQueue.main.async {
    hud.hide(animated: true)
    }
}

You can add the HUD on any view or window. It is however a good idea to avoid adding the HUD to certain UIKit views with complex view hierarchies - like UITableView or UICollectionView. Those can mutate their subviews in unexpected ways and thereby break HUD display.

If you need to configure the HUD you can do this by using the HKProgressHUD reference that show(addedToView:animated:) returns.

let hud = HKProgressHUD.show(addedToView: (self.navigationController?.view)!, animated: true)
hud.mode = .annularDeterminate
hud.label?.text = "Loading..."
DispatchQueue.global(qos: .userInitiated).async {
    // Do something...
    DispatchQueue.main.async {
    hud.hide(animated: true)
    }
}

You can also use a Progress object and HKProgressHUD will update itself when there is progress reported through that object.

let hud = HKProgressHUD.show(addedToView: (self.navigationController?.view)!, animated: true)
hud.mode = .annularDeterminate
hud.label?.text = "Loading..."
let progress = Progress(totalUnitCount: 100)
hud.progressObject = progress;

UI updates should always be done on the main thread.

If you need to run your long-running task in the main thread, you should perform it with a slight delay, so UIKit will have enough time to update the UI (i.e., draw the HUD) before you block the main thread with your task.

HKProgressHUD.show(addedToView: self.view, animated: true)
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + DispatchTimeInterval.seconds(3), execute: {
      // Do something...
      HKProgressHUD.hide(addedToView: self.view, animated: false)
 })

You should be aware that any HUD updates issued inside the above block won't be displayed until the block completes.

For more examples, including how to use HKProgressHUD with asynchronous operations such as NSURLConnection, take a look at the bundled demo project.

License

This code is distributed under the terms and conditions of the MIT license.

Change-log

A brief summary of each HKProgressHUD release can be found in the CHANGELOG.

About

Swift MBProgressHUD

Resources

Readme
MIT license
Activity
Custom properties

Stars

0 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.