Latest | 1.0.0 |
---|---|
Homepage | https://github.com/alberdev/PaintCodeKit |
License | MIT |
Platforms | ios 10.0 |
Frameworks | UIKit |
Authors |
Table of Contents
Description
PaintCodeKit
manage your converted images in PaintCode. You will be able to use your images directly in the views using extensions with correct sizes. Use it to maintain your code clean!
- [x] Import your code from PaintCodeKit
- [x] Customizable images
- [x] Clean code!
- [x] Easy usage
- [x] Supports iOS, developed in Swift 5
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Installation
PaintCodeKit is available through CocoaPods. To install
it, simply add the following line to your Podfile and run pod install
:
pod 'PaintCodeKit'
Then you can import it when you need
import PaintCodeKit
Usage
In the example you can see how to include you own images in UIImageViews
and how to create an UIImage
with PaintCodeManager
. Once you’ve installed the pod, follow next steps. It’s really simple:
Fill your UIImageView
Use PaintCodeImage
enum to fill with images preloaded in this pod.
// This will get imageView frame to get default image size
imageView.draw(PaintCodeImage.user)
// Extended mode
imageView.draw(PaintCodeImage.user, size: CGSize(width: 10, height: 10), color: .white, cached: true)
In other case, make your own enum type with PaintCodeDraw
protocol implementing draw
method. Follow next example:
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)
}
}
}
As you can see above, draw
method, will draw your custom image from PaintCode code. So you must extend PaintCodeImages
and paste PaintCode code generated draw methods:
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()
}
}
Generate a UIImage
Simple ;)
let image = PaintCodeManager.image(PaintCodeImage.user)
Defaults
You can change some default values in 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
Extra
Also you can make use of anyone of the included images in PaintCodeKit
.
/// Example
PaintCodeImage.user
PaintCodeImage | Preview |
---|---|
.user |
![]() |
Author
Alberto Aznar, [email protected]
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
PaintCodeKit is available under the MIT license. See the LICENSE file for more info.
Latest podspec
{ "name": "PaintCodeKit", "platforms": { "ios": "10.0" }, "summary": "PaintCode turn your images into Swift code, PaintCodeKit helps you to add them in your views!", "description": "PaintCodeKit manage your converted images in PaintCode. You will be able to use your images directly in the views using extensions with correct sizes. Use it to maintain your code clean!", "version": "1.0.0", "license": { "type": "MIT", "file": "LICENSE" }, "authors": { "Alberto Aznar": "[email protected]" }, "homepage": "https://github.com/alberdev/PaintCodeKit", "social_media_url": "https://twitter.com/alberdev", "source": { "git": "https://github.com/alberdev/PaintCodeKit.git", "tag": "1.0.0" }, "frameworks": "UIKit", "source_files": "PaintCodeKit/**/*", "swift_versions": "5.0", "swift_version": "5.0" }
Wed, 22 May 2019 10:13:10 +0000