测试已测试 | ✓ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布最新发布版本 | 2017年1月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Niko Mikulicic 维护。
此捆绑包包含我们倾向于在我们许多项目(我们是指Five Agency 的 iOS 团队)中重复使用的 Swift UI 工具函数。我们预计还会添加更多,但在此期间,您可用于/重新使用/升级所有现有代码。有关辅助函数、图像处理、分页、布局和其他有用的片段的任何一切。
没有其他依赖项。
当前支持的安装选项
$ git submodule add https://github.com/fiveagency/ios-five-ui-utils.git
将 FiveUIUtils.xcodeproj
拖入项目导航器。
转到 项目 > 目标 > 构建阶段 > 与二进制文件链接库
,点击 +
并选择 FiveUIUtils.framework
目标。
要运行示例项目,请执行以下操作。
$ git clone https://github.com/fiveagency/ios-five-ui-utils.git YOUR_DESTINATION_FOLDER
FiveUIUtils.xcworkspace
,选择 示例
方案并按 运行
。此方法将构建一切并运行示例应用程序。/**
Screen size category this device falls into.
*/
public static var sizeCategory: ScreenSizeCategory
示例使用
// on iPhone6
DeviceInfo.sizeCategory // iPhone47in
/**
Returns true if this device has the screen size less than or equal to given size category.
*/
public static func hasScreenSizeLessOrEqual(to size: ScreenSizeCategory) -> Bool
示例使用
// on iPhone6
DeviceInfo.hasScreenSizeLessOrEqual(to: .iPhone47in) // true
/**
Re-colors an image with respect to transparency.
*/
public func changeColor(to color: UIColor) -> UIImage
示例使用
let image = UIImage(named: "original") | |
let color = UIColor(red: 0 / 255.0, green: 254 / 255.0, blue: 248 / 255.0, alpha: 1.0) let recoloredImage = image.changeColor(to: color) |
/**
Translates an image by given amount.
*/
public func translate(by point: CGPoint) -> UIImage
示例使用
let point = CGPoint(x: -40, y: 0) let translatedImage = image.translate(by: point) |
/**
Rotates an image by given angle in degrees.
*/
public func rotate(by degrees: CGFloat) -> UIImage
示例使用
let rotatedImage = image.rotate(by: 30) |
/**
Resizes an image to given size.
*/
public func resize(to size: CGSize) -> UIImage
示例使用
let newSize = CGSize(width: 0.4 * image.size.width, height: 0.4 * image.size.height) let resizedImage = image.resize(to: newSize) |
/**
Crops image with rectangle of given size at given position.
*/
public func crop(at point: CGPoint, size: CGSize) -> UIImage
示例使用
let center = CGPoint(x: image.size.width/2, y: image.size.height/2) let croppedImage = image.crop(at: center, size: newSize) |
/**
Color of a single image pixel at normalized coordinates. Lower left corner of the image is at (0,0).
*/
公开函数 pixelColor(at normalizedCoordinates: CGPoint) -> UIColor
示例使用
let sample = image.pixelColor(at: CGPoint(x: 0.5, y: 0.5)) let sampledImage = UIImage(color: sample) |
/**
Calculates content offset for the given page in enclosing scroll view.
*/
公开函数 contentOffset(forPageAtIndex index: Int) -> CGPoint
示例使用
let pager = ScrollViewPager(scrollAxis: .horizontal,
contentInset: 5,
pageLength: 13,
pageSpacing: 2)
pager.contentOffset(forPageAtIndex: 0) // (-5, 0)
pager.contentOffset(forPageAtIndex: 1) // (10, 0)
/**
Calculates the index of a page at specified point in enclosing scroll view.
*/
公开函数 pageIndex(forContentOffset contentOffset: CGPoint) -> Int
示例使用
// halfway point between pages 0 and 1 is (2.5, 0)
pager.pageIndex(forContentOffset: CGPoint(x: 2.4, y: 0)) // 0
pager.pageIndex(forContentOffset: CGPoint(x: 2.6, y: 0)) // 1
/**
Calculates content offset for the target page on which the scrolling should stop.
*/
公开函数 snapContentOffset(_ contentOffset: CGPoint, withVelocity velocity: CGPoint, sensitivity: CGFloat) -> CGPoint
示例使用
pager.snapContentOffset(CGPoint(x: 1.4, y: 0),
withVelocity: CGPoint(x: 1, y: 0),
sensitivity: 1) // (-5, 0)
pager.snapContentOffset(CGPoint(x: 1.6, y: 0),
withVelocity: CGPoint(x: 1, y: 0),
sensitivity: 1) // (10, 0)
/**
Distance between the page and the given content offset in scroll view.
*/
公开函数 distance(fromPageAtIndex index: Int, toContentOffset offset: CGPoint) -> CGFloat
示例使用
pager.distance(fromPageAtIndex: 0,
toContentOffset: CGPoint(x: 2.4, y: 0)) // 7.4
/**
Normalized distance between the page and the given content offset in scroll view. Content offsets of two adjacent pages have normalized distance equal to 1.
*/
公开函数 normalizedDistance(fromPageAtIndex index: Int, toContentOffset offset: CGPoint) -> CGFloat
示例使用
pager.normalizedDistance(fromPageAtIndex: 0,
toContentOffset: CGPoint(x: 2.4, y: 0)) // 0.49333
/**
- parameter bottomConstraint: Constraint to modify in order to fit in the keyboard.
- parameter view: View which contains `bottomConstraint`.
- parameter targetConstant: The value of `bottomConstraint` constant when keyboard is raised.
*/
公开构造函数 init(withBottomConstraint bottomConstraint: NSLayoutConstraint, inView view: UIView, targetConstant: CGFloat)
示例使用
/**
The number of active tasks.
*/
公开属性 taskCount: Int
/**
Turns network activity indicator on if it wasn't previously activated.
*/
公开函数 startActivity()
/**
Turns network activity indicator off only if there aren't any currently active tasks.
*/
公开函数 endActivity()
示例使用
五个 UI 工具库团队(按字母顺序排列)
Ivan Vranjić
Kristijan Rožanković
Miran Brajsa
Niko Mikuličić
FiveUIUtils 在 MIT 许可下可用。更多信息请参阅 LICENSE 文件。