一个跨平台框架,提供易于使用的便捷属性、函数和重载运算符。
你可以使用以下方式导入此模块:
import DLCoreGraphics
常见的操作是在计算视图布局时对数字进行四舍五入/向上取整/向下取整。 为了简化工作,这些函数已经为CGPoint
、CGSize
和CGRect
进行了重载。 由于我们在为具有不同比例的设备进行布局,因此基于设备比例进行舍入操作会很有帮助。 因此,有 3 个新的函数可用:screenRound
、screenCeil
和screenFloor
。
一些运算符的例子
var point = CGPoint(x: 10.0, y: 20.0)
let otherPoint = CGPoint(x: 40.0, y: 30.0)
point += otherPoint
// point == CGPoint(x: 50.0, y: 50.0)
let size = CGSize(width: 100, height: 100.0)
let newSize = size * 3
// newSize == CGSize(width: 300, height: 300.0)
查找矩形右侧的中间点
let rectangle = CGRect(x: 10.0, y: 20.0, width: 100, height: 100.0)
let middle = rectanle.middle(forSide: .right)
// middle == CGPoint(x: 110.0, y: 70.0)
还有更多功能可用;请查看框架以获取完整详细信息。
github "davidlivadaru/DLCoreGraphics"
如果只需要适用于单个操作系统的框架,那么我建议在执行 carthage update
时使用 --platform [iOS|macOS|watchOS|tvOS]
说明符。
在您的 Podfile
中添加依赖项。
pod 'DLCoreGraphics'
注意:目前使用 CocoaPods 不支持 watchOS,请改用 Carthage。
在您的 Package.swift
中添加以下依赖项
dependencies: [
.package(url: "https://github.com/davidlivadaru/DLCoreGraphics.git", .upToNextMajor(from: "1.0.0"))
]
并更新你的目标依赖项
targets: [
.target(
name: "YourTargetName",
dependencies: ["DLCoreGraphics"])),
]
该模块已通过单元测试覆盖,但是,错误总是会遗漏。 如果你在模块中发现错误,请创建一个 issue。
如果您想为修复错误或实现新功能做出贡献,请创建一个 pull request。
DLCoreGraphics 在 MIT 许可下发布。 有关详细信息,请参阅 LICENSE。