Swift 4.0
inkkit 默认支持 Swift 4.0,因此只需在你的 podfile 中包含 inkkit 即可使用。
pod 'InkKit'
Swift 3.2
要在 Swift 3.2/3.0 项目中使用 inkkit,确保指向 2.1.0
标签。
pod 'InkKit', '2.1.0'
Swift 2.3
为了在 Swift 2.3 项目中使用 inkkit,确保指向 swift2.3
分支。
pod 'InkKit', :git => 'https://github.com/shaps80/InkKit/', :branch => 'swift2.3'
Swift 2.2
如果你仍然需要 Swift 2.2,可以将版本指向如下: pod 'InkKit', '1.3.1'
在这里看到的一切都是使用 inkkit 代码绘制的!实际上,除了一些 CGRect
实例外,这是绘制右侧图像所需的所有代码 ;)
v2.0.0
注意:由于这是一个 Swift 3 版本,我决定同时清理 API 并移除所有弃用警告。inkkit 2.0 应被视为新的 API。
v1.3.1
v1.2.0
v1.1.0
v1.0
inkkit 提供许多有用的便利方法用于绘制和几何计算。它还可以跨平台工作,在 iOS & MacOS 上使用。
如果以下便利方法不能解决你的需求,你可以直接使用添加到 CGContext
的新方法开始。
func draw(inRect:attributes:drawing:)
在用法上如下所示
CGContext.current?.draw(inRect: rect, drawing: { (context, rect, attributes) in
Color.redColor.setFill()
UIRectFill(rect)
})
这基本上封装了获取上下文、设置其框架和保存/恢复调用。如果你提供了额外的 DrawingAttributes 块,它还会为你预先配置上下文选项。
init(colCount:rowCount:bounds:)
func positionForCell(atIndex:) -> (col: Int, row: Int)
func boundsForCell(atIndex:) -> CGRect
func boundsForRange(sourceColumn:sourceRow:destinationColumn:destinationRow:) -> CGRect
func boundsForCell(col:row:) -> CGRect
func enumerateCells(enumerator:(index:col:row:bounds:) -> Void)
使用网格可以非常方便地排列绘图,无需考虑位置、矩形转换等因素...
我通常只用于布局,但有时也能将其作为渲染内容使用(例如在提供的演示中)。
// components is a bitmask [ .Outline, .Rows, .Columns ]
func stroke(components:attributes:)
支持.Outer
、.Inner
和.Center
边框,以及.Outer
和.Inner
阴影。
static func addBorder(type:path:attributes:)
static func addShadow(type:path:color:radius:offset:)
static func strokeLine(startPoint:endPoint:startColor:endColor:angleInDegrees:attributes:)
static func strokeLine(startPoint:endPoint:color:attributes:)
static func strokePath(path:startColor:endColor:angleInDegrees:attributes:)
static func fillPath(path:startColor:endColor:angleInDegrees:attributes:)
许多绘图方法使用了下面的几何功能,但它们也可以用于您自己的项目。
func divide(atDelta:fromEdge:margin:) -> (slice, remainder)
func insetBy(edgeInsets:) -> CGRect
mutating func insetInPlace(edgeInsets:)
func alignedTo(rect:horizontal:vertical:) -> CGRect
func scaledTo(rect:scaleMode:) -> CGRect
func gradientPoints(forAngleInDegrees:) -> (start, end)
func scaledTo(size:scaleMode:) -> CGSize
func reversibleRect(fromPoint:toPoint:) -> CGRect
还有一些针对图像的额外绘图方法。
func drawAlignedTo(rect:horizontal:vertical:blendMode:alpha:)
func drawScaledTo(rect:scaleMode:blendMode:alpha:)
static func circle(radius:attributes:) -> Image
static func draw(width:height:scale:attributes:drawing:) -> Image
static func draw(size:scale:attributes:drawing:) -> Image
最后,我们还提供了一些简单的字符串绘图方法。
func drawAlignedTo(rect:horizontal:vertical:attributes:constrainedSize:)
func sizeWithAttributes(attributes:constrainedSize:) -> CGSize
func drawAtPoint(point:attributes:)
func drawInRect(rect:withAttributes)
要亲自尝试,请下载源代码并运行 Included 演示项目。
InkKit 支持以下平台
InkKit 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'InkKit'
或者,您可以直接将文件拖放到 iOS 或 OSX 项目中。
InkKit 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。