指标 1.3.1

指标 1.3.1

Marlo Kessler 维护。



指标 1.3.1

  • 作者
  • Marlo Kessler

Indicators

本包包含一组纯 SwiftUI 编写的指标。

The different Indicators

入门

Swift 包管理器

要开始使用,请通过 Swift 包管理器添加包依赖。因此,在 Xcode 中打开您的项目。在菜单中选择 文件>Swift 包>添加依赖

Click on Add Dependency.

然后搜索 指标 并从 Connapptivity 选择 SwiftUI-Indicators

Select SwiftUI-Indicators from Connapptivity.

现在选择您想添加的版本以及目标,然后单击 完成 以导入包。最后,您应该在项目导航器中的 Swift Pakckage Dependencies 下看到它。

You can see the package in the navigator.

CocoaPods

或者,您可以使用 Cocoapods。只需将其添加到 Podfile 中。

pod 'Indicators'

即可。

在您的代码中使用指标时,只需在 Swift 代码文件顶部添加 import Indicators 语句。

常规

指标类型

本软件包包含六种指标类型和七个不同指标。支持的指标有

成功指标

SuccessIndcator()

失败指标

FailureIndcator()

信息指标

InfoIndcator()

等待指标

CircularWaitingIndcator()

LinearWaitingIndcator()

进度指标

CircularProgressIndcator()

LinearProgressIndcator()

定制

每个指标都可以通过几种方式进行定制

Indicator()

// Set a custom foregroundcolor.
.foregoundColor(Color?)

// Set a custom linewidth.
.lineWidth(Double)

// Set the animation pace of the indicator.
.pace(Double)

// Set if indicator changes should be animated. The default value is true.
.animated(Bool = true)

// Set your custom animation to the indicator
.animation(Animation?)

等待和进度指标可以进一步定制。要查看这些选项,请参阅下面的文档。

等待和进度指标显示文本

您可以选择在等待和进度指标中显示文本。该文本可以直接在初始化器中声明

WaitingIndicator(Double, text: String?)

ProgressIndicator(Double, text: String?)

对于圆形指标,文本将根据指标的大小自动缩放。指标总是尝试显示整个文本并避免覆盖。

The text resizes automatically.

对于线性指标,文本不会自动缩放。您可以按需调整字体。

LinearIndicator()
    .font(Font?)

指标底部与文本基线对齐,因此设计总是看起来很好。

The indicators bottom is aligned to the text base.

进度指标更改背景描边颜色

为了使用户直观地感受到某个过程相对于整个过程有多少进度,进度指标有一个背景描边。您可以选择更改描边颜色,或者将其设置为透明,如果您不希望有背景描边。

ProgressIndicator()
    .backgroundColor(Color?)

自定义指标

您还可以通过实现 Indicator 协议来创建自定义指标。

struct CustomIndicator: Indicator { ...

为此包贡献力量

此包为公开状态,因为希望贡献的人都可以做到。我们相信没有比社区开发更强大的了。因此,请随意分支并为此包添加你的代码。