ProgressHUD Documentation

repository·master·Indexed 25 days ago

https://github.com/relatedcode/progresshud

A SwiftUI-based tool for iOS providing non-disruptive HUD alerts, notifications, and progress indicators. Includes guides on installation via Swift Package Manager, integration using the .progressHUD() modifier, and customization of visual attributes, animations, and icons.

Tokens
1.5K
Snippets
5
Records
7
Agent score
34%

What's inside ProgressHUD

  1. Set up ProgressHUD in SwiftUI

    master

    To enable ProgressHUD in your SwiftUI application, add the .progressHUD() modifier to your root view (typically in your @main App struct).

    import SwiftUI
    
    @main
    struct MyApp: App {
        var body: some Scene {
            WindowGroup {
                ContentView()
                    .progressHUD()
            }
        }
    }
  2. Install ProgressHUD via Swift Package Manager

    master

    To add ProgressHUD as a dependency to your Xcode project:

    1. Open your Swift project in Xcode.
    2. Navigate to File -> Add Package Dependencies....
    3. Paste https://github.com/relatedcode/ProgressHUD.git into the search bar.
    4. Choose the version you want to use and click Add Package.
  3. Customize ProgressHUD appearance

    master

    You can modify the visual attributes of the HUD globally using ProgressHUD properties. This includes colors, fonts, sizes, and images for both the main HUD and banners.

    // General HUD Customization
    ProgressHUD.animationType = .circleStrokeSpin
    ProgressHUD.colorHUD = .gray.opacity(0.1)
    ProgressHUD.colorBackground = .gray.opacity(0.3)
    ProgressHUD.colorAnimation = .blue
    ProgressHUD.colorProgress = .blue
    ProgressHUD.colorStatus = .primary
    ProgressHUD.mediaSize = 100
    ProgressHUD.marginSize = 50
    ProgressHUD.fontStatus = .system(size: 24, weight: .bold)
    ProgressHUD.imageSuccess = Image("success")
    ProgressHUD.imageError = Image("error")
    
    // Banner Customization
    ProgressHUD.colorBanner = .blue.opacity(0.1)
    ProgressHUD.colorBannerTitle = .primary
    ProgressHUD.colorBannerMessage = .secondary
    ProgressHUD.fontBannerTitle = .system(size: 16, weight: .semibold)
    ProgressHUD.fontBannerMessage = .system(size: 14)
  4. Display HUD alerts and notifications

    master

    Use the ProgressHUD static methods to trigger various HUD states such as banners, animations, success/error indicators, and progress bars.

    // Banners
    ProgressHUD.banner("Banner title", "Banner message to display.")
    ProgressHUD.banner("Banner title", "Message to display.", delay: 2.0)
    ProgressHUD.bannerHide()
    
    // Animations and Loading
    ProgressHUD.animate("Some text...")
    ProgressHUD.animate("Some text...", interaction: false)
    ProgressHUD.animate("Please wait...", .ballVerticalBounce)
    ProgressHUD.animate("Loading...", symbol: "star.fill")
    
    // Status Indicators
    ProgressHUD.succeed()
    ProgressHUD.succeed("Some text...", delay: 1.5)
    ProgressHUD.failed()
    ProgressHUD.failed("Some text...")
    ProgressHUD.success("Success message")
    ProgressHUD.error("Error message")
    ProgressHUD.added("Item added")
    
    // Progress Bars
    ProgressHUD.progress(0.15)
    ProgressHUD.progress("Loading...", 0.42)
    
    // Symbols
    ProgressHUD.symbol(name: "box.truck")
    ProgressHUD.symbol("Some text...", name: "sun.max")
    
    // Dismissal
    ProgressHUD.dismiss()
    ProgressHUD.remove()
  5. Reference AnimationType enums

    master

    The AnimationType enum defines the available animation styles for the HUD.

    public enum AnimationType: CaseIterable {
    	case none
    	case activityIndicator
    	case ballVerticalBounce
    	case barSweepToggle
    	case circleArcDotSpin
    	case circleBarSpinFade
    	case circleDotSpinFade
    	case circlePulseMultiple
    	case circlePulseSingle
    	case circleRippleMultiple
    	case circleRippleSingle
    	case circleRotateChase
    	case circleStrokeSpin
    	case dualDotSidestep
    	case horizontalBarScaling
    	case horizontalDotScaling
    	case pacmanProgress
    	case quintupleDotDance
    	case semiRingRotation
    	case sfSymbolBounce
    	case squareCircuitSnake
    	case triangleDotShift
    }