GTProgressBar 0.3.3

GTProgressBar 0.3.3

测试已测试
语言语言 SwiftSwift
授权协议 MIT
发布最新发布2019 年 5 月
SPM支持 SPM

Grzegorz Tatarzyn 维护。



  • gregttn

GTProgressBar

CI Status Carthage compatible Version License Platform

GTProgressBar 是一个可定制的进度条。它支持水平和垂直方向,您可以调整许多进度条的视觉设置以适应您的用例。定制可以通过 Interface Builder 和代码完成。以下是示例应用中的预览

Preview

示例应用

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

要求

此组件使用 Swift 4 编写,因此您需要运行 Xcode 9 或更高版本。

用法

GTProgressBar 的许多属性都可以配置。其中大部分可以在 Interface Builder (@IBInspectable) 中配置。

  • orientation: GTProgressBarOrientation 此属性允许您指定条的排列方向: horizontalvertical。默认设置为水平

    progressBar.orientation = GTProgressBarOrientation.vertical
  • @IBInspectable orientationInt: Int 该属性允许您以整数值指定进度条的方位。默认值为水平。当前映射如下:

    0 -> GTProgressBarOrientation.horizontal

    1 -> GTProgressBarOrientation.vertical

    progressBar.orientationInt = 1
  • direction: GTProgressBarDirection 该属性允许您指定进度条内容的方向:顺时针逆时针。默认设置为顺时针

    progressBar.direction = GTProgressBarDirection.anticlockwise
  • @IBInspectable directionInt: Int 该属性允许您以整数值指定进度条内容的方向。默认值为顺时针。当前映射如下:

    0 -> GTProgressBarDirection.clockwise

    1 -> GTProgressBarDirection.anticlockwise

    progressBar.orientationInt = 1
  • @IBInspectable progress: CGFloat

    该属性指定了进度条填充的量。允许的值是从 0.0 到 1.0。默认值为 0。如果显示进度标签,这里的值将以百分比的形式显示。以下示例将使进度条填充 50%,标签将显示 50%

    progressBar.progress = 0.5
  • @IBInspectable displayLabel: Bool

    该属性指定是否应显示进度标签。默认值为 true

    progressBar.displayLabel = false
  • @IBInspectable barBorderColor: UIColor

    该属性指定了进度条边框的颜色。默认值为 UIColor.black

    progressBar.barBorderColor = UIColor(red:0.35, green:0.80, blue:0.36, alpha:1.0)
  • @IBInspectable barBackgroundColor: UIColor

    该属性指定了进度条在控件内的背景颜色。默认值为 UIColor.white

    progressBar.barBackgroundColor = UIColor(red:0.77, green:0.93, blue:0.78, alpha:1.0)
  • @IBInspectable barFillColor: UIColor

    该属性指定了进度条的填充颜色。默认值为 UIColor.white

    progressBar.barFillColor = UIColor(red:0.35, green:0.80, blue:0.36, alpha:1.0)
  • @IBInspectable barBorderWidth: CGFloat

    该属性指定了进度条边框的宽度。默认值为 2

    progressBar.barBorderWidth = 1
  • @IBInspectable barFillInset: CGFloat

    该属性指定了进度条填充和边框之间的间隔。默认值为 2

    progressBar.barFillInset = 1
  • @IBInspectable labelTextColor: UIColor

    该属性指定了标签的填充颜色。默认值为 UIColor.black

    progressBar.labelTextColor = UIColor(red:0.35, green:0.80, blue:0.36, alpha:1.0)
  • progressLabelInsets: UIEdgeInsets

    该属性指定了进度标签的间隔。默认值为 UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)

    progressBar.progressLabelInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
  • @IBInspectable progressLabelInsetLeft: CGFloat

    该属性允许您在 Interface Builder 中指定 progressLabelInsets 的左间隔属性。默认值为 0。

    progressBar.progressLabelInsetLeft = 5.0
  • @IBInspectable progressLabelInsetRight: CGFloat

    该属性允许您在 Interface Builder 中指定 progressLabelInsets 的右间隔属性。默认值为 0。

    progressBar.progressLabelInsetRight = 5.0
  • @IBInspectable progressLabelInsetTop: CGFloat

    该属性允许您在 Interface Builder 中指定 progressLabelInsets 的顶部间隔属性。默认值为 0。

    progressBar.progressLabelInsetTop = 5.0
  • @IBInspectable progressLabelInsetBottom: CGFloat

    该属性允许您在 Interface Builder 中指定 progressLabelInsets 的底部间隔属性。默认值为 0。

    progressBar.progressLabelInsetBottom = 5.0
  • @IBInspectable cornerRadius: CGFloat

    该属性指定了圆角半径。默认值为 0.0

    progressBar.cornerRadius = 10.0
  • font: UIFont

    该属性允许您指定进度标签的字体。默认值为 UIFont.systemFont(ofSize: 12)

    progressBar.font = UIFont.boldSystemFont(ofSize: 18)
  • barMaxHeight: CGFloat?

    该属性允许您指定进度条的最大高度。默认情况下,进度条的大小将匹配整个视图的高度。如果最大高度比可用的视图高度大,则会被忽略。

    progressBar.barMaxHeight = 12
  • @IBInspectable barMaxHeightInt: Int

    该属性允许您在 Interface Builder 中以整数值指定进度条的最大高度。默认情况下,进度条的大小将匹配整个视图的高度。如果最大高度比可用的视图高度大,则会被忽略。如果将此属性设置为 0,则将对进度条的高度没有限制。

    progressBar.barMaxHeightInt = 12
  • barMaxWidth: CGFloat?

    此属性允许您指定进度条的最大宽度。默认情况下,进度条的宽度将与可用宽度相匹配。如果最大宽度大于可用宽度,则会被忽略。

    progressBar.barMaxWidth = 12
  • @IBInspectable barMaxWidthInt: Int

    此属性允许您在界面构建器中将进度条的最大宽度指定为一个整数。默认情况下,进度条的宽度将与可用宽度相匹配。如果最大宽度大于可用宽度,则会被忽略。如果您将此属性设置为0,则不会对条的宽度有任何限制。

    progressBar.barMaxWidthInt = 12
  • labelPosition: GTProgressBarLabelPosition

    此属性允许您指定进度标签应放置的侧面。默认为 GTProgressBarLabelPosition.left

    progressBar.labelPosition = GTProgressBarLabelPosition.right
  • @IBInspectable labelPositionInt: Int

    此属性允许您在界面构建器中通过整数指定进度标签的位置。当前映射如下:

    0 -> GTProgressBarLabelPosition.left

    1 -> GTProgressBarLabelPosition.right

    2 -> GTProgressBarLabelPosition.top

    3 -> GTProgressBarLabelPosition.bottom

    progressBar.labelPosition = GTProgressBarLabelPosition.right
  • cornerType: GTProgressBarCornerType

    此属性允许您指定角落类型(方形或圆形)。默认为 GTProgressBarCornerType.rounded

    progressBar.cornerType = GTProgressBarCornerType.square
  • @IBInspectable cornerTypeInt: Int

    此属性允许您在界面构建器中通过整数指定角落的类型。当前映射如下:

    0 -> GTProgressBarCornerType.square

    1 -> GTProgressBarCornerType.rounded

    progressBar.cornerTypeInt = GTProgressBarCornerType.rounded.rawValue
  • animateTo(progress: CGFloat, completion: (() -> Void)?)

    此方法将进度条动画到指定的值。允许的值从0.0到1.0。如果提供了无效的值,则会被限制到最近的允许值。此方法还接受一个回调,当动画完成时执行。

    progressBar.animateTo(progress: 0.9) {
      print("Animation completed")
    }

将所有这些综合起来,以下是代码中GTProgressBar的示例配置:

let progressBar = GTProgressBar(frame: CGRect(x: 0, y: 0, width: 300, height: 15))
progressBar.progress = 1
progressBar.barBorderColor = UIColor(red:0.35, green:0.80, blue:0.36, alpha:1.0)
progressBar.barFillColor = UIColor(red:0.35, green:0.80, blue:0.36, alpha:1.0)
progressBar.barBackgroundColor = UIColor(red:0.77, green:0.93, blue:0.78, alpha:1.0)
progressBar.barBorderWidth = 1
progressBar.barFillInset = 2
progressBar.labelTextColor = UIColor(red:0.35, green:0.80, blue:0.36, alpha:1.0)
progressBar.progressLabelInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
progressBar.font = UIFont.boldSystemFont(ofSize: 18)
progressBar.labelPosition = GTProgressBarLabelPosition.right
progressBar.barMaxHeight = 12
progressBar.direction = GTProgressBarDirection.anticlockwise

view.addSubview(progressBar)

安装

Carthage

要安装它,只需将以下行添加到您的Cartfile中

github "gregttn/GTProgressBar"

CocoaPods

要安装它,只需将以下行添加到您的Podfile中

pod "GTProgressBar"

作者

gregttn, [email protected]

许可证

GTProgressBar 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。