UIToolBox 1.0.6

UIToolBox 1.0.6

Brandon 维护。



UIToolBox 1.0.6

  • 作者:
  • buba447

UIToolBox

Version License Platform

UIToolBox 是一套用于 Swift 编写 iOS UI 的工具、扩展和类。其中许多扩展是缺失的功能和易于使用的辅助器,用于创建可读性高的代码。

该库分为三个主要部分:

  • Auto Layout 扩展:用于创建和动画约束的易于使用扩展。
  • Foundation 扩展:许多 Foundation 对象的缺失功能和辅助器。(例如,添加、减去、乘以两个 CGPoints!获取 UIColor 的互补色)
  • UI 扩展:几个常见 UI 功能的清洁和易于使用的辅助函数。

有关完整功能列表,请参阅下面的文档。

安装

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

pod 'UIToolBox'

示例

Example

例如,我们想通过 AutoLayout 创建一个动画位置和大小的视图。

import UIKit
import UIToolBox

let view = UIView()

/// Create a color with Hue Saturation and Brightness
let color = UIColor(hue: 0.5, saturation: 1, brightness: 1, alpha: 1)

/// Set the view background color to be a dark complementary color.
view.backgroundColor = color.complementary.withBrightness(brightness: 0.2)

/// Create a view with the color
let colorView = UIView(backgroundColor: color)
colorView.cornerRadius = 12
view.addSubview(colorView)

/// Make a constraint group that pins the colorView to the top, leading and traling, with a height of 50
let topConstraint = ConstraintGroup(constraints: [
colorView.alignTopToView(view),
colorView.constrainHeight(50),
colorView.alignLeadingToView(view),
colorView.alignTrailingToView(view)
])

/// Make a constraint group that pins the colorView to the bottom, leading and trailing with a padding of 20, and a height of 72
let bottomConstraint = ConstraintGroup(constraints: [
colorView.alignBottomToView(view, constant: 30),
colorView.constrainHeight(72),
colorView.alignLeadingToView(view, constant: 20),
colorView.alignTrailingToView(view, constant: 20)
])

/// Set the top constraint to enabled, the bottom to disabled.
topConstraint.enable()
bottomConstraint.disable()
view.layoutIfNeeded()

/// Now lets animate from one constraint group to another with a spring animation.

topConstraint.disable()
bottomConstraint.enable()
view.animateLayoutChanges(
style: .slowSpring,
withAnimation: {
/// Animate the background color to its complementary.
colorView.backgroundColor = color.complementary
}) { (complete) in
/// Animation complete!
}

文档

在此处阅读完整文档

作者

Brandon Withrow, [email protected]

许可

UIToolBox遵从MIT许可。有关更多信息,请参阅LICENSE文件。