iStatusView 0.3.0

iStatusView 0.3.0

Andreas Wulf维护。



  • awulf

iStatusView

Version License Platform

示例

要运行示例项目,首先克隆仓库,然后在 Example 目录中运行 pod install

需求

安装

iStatusView 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile

pod 'iStatusView'

Loading Screen Shot Error Screen Shot

集成

步骤 1:使用外观代理样式化状态视图

StatusView.appearance().titleLabelTextColor = UIColor.black
StatusView.appearance().titleLabelFont = UIFont.boldSystemFont(ofSize: 18)

StatusView.appearance().messageLabelTextColor = UIColor(white: 0.2, alpha: 1.0)
StatusView.appearance().messageLabelFont = UIFont.systemFont(ofSize: 16)
StatusView.appearance().backgroundColor = UIColor.white

步骤 2:构建一个用于显示的加载视图

您可以添加您喜欢的任何加载指示器

使用 UIActivityIndicator 的示例

let loadingView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.whiteLarge)
loadingView.color = UIColor.black
loadingView.startAnimating()
loadingView.bounds = CGRect(x: 0, y: 0, width: 80, height: 80)

步骤 3:创建状态视图

使用方便的创建函数,你必须传入一个加载视图(即使它只是一个空的 UIView,否则将不会工作)

self.statusView = StatusView.create(with: loadingView, addTo: self.view)

设置大小,在这种情况下我们使用 SnapKit 设置 AutoLayout 约束以填充整个视图。也可以使用 AutoResizingMasks、StoryBoard 或其他声明式 AutoLayout 代码

self.statusView.snp.makeConstraints { (make) in
    make.edges.equalToSuperview()
}

步骤 4(可选):监听按钮点击。

当设置状态时,会出现一个按钮,当设置按钮图像时非常有用,例如重试按钮或取消加载按钮

self.statusView.button.addTarget(self, action: #selector(statusViewButtonPressed), for: .touchUpInside)

步骤 5:显示一个状态

state:状态视图所处的状态。loading将显示加载指示器,message将隐藏加载指示器,hidden将隐藏整个状态视图。title:可选;是状态的主要标题。message:可选;是要显示的更详细的消息。statusImage:可选;显示要显示的图像。buttonImage:可选;当一个图像被设置时,它将显示为一个可点击的按钮。

try? self.statusView.changeTo(
        state: .loading,
        title: "Title of status",
        message: "More info on the status",
        statusImage: nil,
        buttonImage: nil,
        animate: false)

根据内容加载状态,在此将状态设置为 .hidden 或 .message

许可协议

iStatusView 在Apache许可证下可用。更多信息请参阅 LICENSE 文件。