Giter Club home page Giter Club logo

chrysan's Introduction

Chrysan

CI Status Version Language License Platform twitter weibo

Chrysan 是一个简单易用的 HUD 库,使用 iOS 自带的 UIBlurEffect 毛玻璃特效。

使用基于 UIViewPropertyAnimator 的动画,可以自定义想要的效果

多种内置的指示器效果,同样支持自定义,并且支持 GIF 动图

进度指示器,内置环形和条形进度指示器,支持自定义进度文字和颜色

静态状态指示器, 内置带动画的成功和失败指示器,支持自定义路径动画

支持自定义扩展更多状态,支持自定义图标指示器,支持使用系统内置 SF Symbols 作为图标

纯文本展示,支持单行和多行文本

适配

Chrysan 2.x 是一个完全重写的版本,以支持更多的指示器类型、更多的动画配置,以及完全开放的自定义 API。

Chrysan 2.x 支持 iOS 11+ 以及 Swift 5.3+。如需支持更早的版本,请使用 1.x 版。

安装

注意:Chrysan 依赖 SnapKit 5.x 进行 UI 布局,确保你没有引用与其冲突的其他第三方库

通过 CocoaPods 安装

pod 'Chrysan'

通过 SPM 安装

向 Package.swift 添加依赖:

dependencies: [
    .package(url: "https://github.com/Harley-xk/Chrysan.git", .upToNextMajor(from: "2.0.0")),
],

通过 Carthage 安装

github "Harley-xk/Chrysan"

在命令行执行 carthage update 来完成编译,然后将 Chrysan.framework 添加到你的项目中。

确保将 Chrysan.framework 添加到 target 的 Embedded Binaries 配置项中

使用

在 ViewController 中访问 Chrysan

通过 viewController.chrysan 方法可以访问当前视图控制器的 chrysan 组件并自动创建。chrysan 会自动添加到 viewController 的根视图。

快速显示 Chrysan

chrysan.changeStatus(to: .loading(message: "正在加载"))

显示进度

let progress = 0.1

// 显示进度
chrysan.changeStatus(to: .progress(message: "正在下载", progress: progress))

// 自定义进度文字
chrysan.changeStatus(to: .progress(message: "正在下载", progress: progress, progressText: "325/512"))

隐藏 Chrysan

// 立刻隐藏 chrysan
chrysan.hide()
// 1 秒后隐藏 chrysan
chrysan.hide(afterDelay: 1)

预设状态

Chrysan 内置了多种状态可以使用:

public extension Status {
    /// 预设状态:静默状态
    static let idle = Status(id: .idle)

    /// 纯文本的状态,此时一般只显示文本内容
    /// - Parameter message: 文本内容,支持多行
    static func plain(message: String) -> Status {
        return Status(id: .plain, message: message)
    }

    /// 加载中状态, 所有的 loading 状态都具有相同的 id
    /// - Parameter message: 自定义消息内容
    static func loading(message: String? = nil) -> Status {
        return Status(id: .loading, message: message)
    }

    /// 预设状态:带进度的状态,所有的 progress 状态都具有相同的 id
    static func progress(
        message: String? = nil,
        progress: Double,
        progressText: String? = nil
    ) -> Status {
        return Status(
            id: .progress,
            message: message,
            progress: progress,
            progressText: progressText
        )
    }

    /// 预设状态:成功
    static func success(message: String? = nil) -> Status {
        return Status(id: .success, message: message)
    }

    /// 预设状态:失败
    static func failure(message: String? = nil) -> Status {
        return Status(id: .failure, message: message)
    }
}

更多内容请查看示例以及代码注释。

chrysan's People

Contributors

harley-xk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.