PaintCodeKit 1.0.0

PaintCodeKit 1.0.0

Alberto Aznar 维护。



PaintCodeKit logo

PaintCodeKit

Version License Platform Swift

目录

描述

PaintCodeKit manages your converted images in PaintCode. You will be able to use your images directly in the view using extensions with correct sizes. Use it to maintain clean code!

  • 导入您的 PaintCodeKit 代码
  • 可定制的图像
  • 干净代码
  • 易于使用
  • 支持 iOS,使用 Swift 5 开发

示例

To run the example project, clone the repo, and run pod install from the Example directory first.

安装

PaintCodeKit可通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中,然后运行pod install

pod 'PaintCodeKit'

在需要时您就可以导入它

import PaintCodeKit

使用方法

在示例中您可以看到如何在UIImageViews中包含您自己的图像,以及如何使用PaintCodeManager创建UIImage。安装pods后,按照以下步骤操作。非常简单

填充您的UIImageView

使用PaintCodeImage枚举来填充本插件中预加载的图像。

imageView.draw(PaintCodeImage.user)

在其他情况下,创建一个包含实现draw方法的PaintCodeDraw协议的自定义枚举类型。请参考以下示例

enum Icon: PaintCodeDraw {

    case shareApp
    case bell

    func draw(size: CGSize, color: UIColor) {
        switch self {
        case .shareApp: PaintCodeImages.drawShareApp(frame: CGRect(origin: .zero, size: size), resizing: .aspectFit)
        case .bell: PaintCodeImages.drawBell(frame: CGRect(origin: .zero, size: size), resizing: .aspectFit)
        }
    }
}

如上图所示,draw方法将根据PaintCode代码绘制您自定义的图像。因此,您必须扩展PaintCodeImages并将生成的draw类粘贴进去

extension PaintCodeImages {

    class func drawShareApp(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 400, height: 400), resizing: ResizingBehavior = .aspectFit) {

        /// General Declarations
        let context = UIGraphicsGetCurrentContext()!

        /// Resize to Target Frame
        context.saveGState()
        let resizedFrame = resizing.apply(rect: CGRect(x: 0, y: 0, width: 24, height: 24), target: targetFrame)
        context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
        context.scaleBy(x: resizedFrame.width / 24, y: resizedFrame.height / 24)

        /// Combined Shape
        let combinedShape = UIBezierPath()
        combinedShape.move(to: CGPoint(x: 10, y: 3.41))
        combinedShape.addLine(to: CGPoint(x: 10, y: 14))
        combinedShape.addCurve(to: CGPoint(x: 9, y: 15), controlPoint1: CGPoint(x: 10, y: 14.55), controlPoint2: CGPoint(x: 9.55, y: 15))
        combinedShape.addCurve(to: CGPoint(x: 8, y: 14), controlPoint1: CGPoint(x: 8.45, y: 15), controlPoint2: CGPoint(x: 8, y: 14.55))
        combinedShape.addLine(to: CGPoint(x: 8, y: 3.41))
        [...]

        context.restoreGState()
    }
}

生成一个UIImage

简单 ;)

let image = PaintCodeManager.image(PaintCodeImage.user)

默认值

您可以在PaintCodeManager中更改一些默认值

/// Image size
PaintCodeManager.shared.defaultSize = CGSize(width: 30, height: 30)

/// Default image color
PaintCodeManager.shared.defaultColor = UIColor.black

/// Cache generated images
PaintCodeManager.shared.defaultCached = true

附加信息

您还可以使用PaintCodeImage枚举中包含的任何图像

/// User image
PaintCodeImage.user

作者

Alberto Aznar,[email protected]

贡献

  1. 将它“分叉”吧!
  2. 创建你的功能分支: git checkout -b my-new-feature
  3. 提交你的更改: git commit -am '添加某些功能'
  4. 推送到分支: git push origin my-new-feature
  5. 提交拉取请求 :D

许可证

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