Sketch plugin to generate ios view code
exports your views as UIBezierPath as swift code so you'll have something like
let path = UIBezierPath()
path.moveToPoint(...)
...
It's very annoying to draw in ios in code. But it's annoying to draw in sketch and export it as a picture because you can no longer use the CGRect dimensions from ios. You're stuck with whatever dimensions you picked in sketch.
This will generate a bunch of swift functions, with 1 main function which takes in a CGRect so you can put it in layoutSubviews. All your shapes will be relative to how you depict them in sketch and the CGRect. Also you can edit the code and add your own transformations or animations, instead of having to create a ton of assets and load them dynamically.
For instance, if in sketch you offset your creation 20px from the left, and your arboard is 200px in width. Then at runtime of the ios application your creation will be offset 20*(width/200) where width is the width of the ios CGRect at runtime. This of course works with y offset, width, and height.
When you run the plugin it puts the generated code into your artboard, so if you have a very complex shape (or groups of shapes) pasting the code might be slow or even crash sketch. If it is complex and hasn't crashed, it might take minutes (spinning beachball) but it will work.

lazy var outline: CAShapeLayer = {
let l = CAShapeLayer()
l.lineWidth = 28
l.strokeColor = UIColor(hue: 0, saturation: 0, brightness: 1, alpha: 1).CGColor
l.fillColor = UIColor(hue: 0, saturation: 0, brightness: 1, alpha: 1).CGColor
self.layer.addSublayer(l)
return l
}()
...
func moo(bounds: CGRect) {
outline.frame = bounds
outline.path = outline_path(outline.frame)
body.frame = bounds
body.path = body_path(body.frame)
spot2.frame = bounds
spot2.path = spot2_path(spot2.frame)
spot.frame = bounds
spot.path = spot_path(spot.frame)
armLeft.frame = bounds
armLeft.path = armLeft_path(armLeft.frame)
armRight.frame = bounds
armRight.path = armRight_path(armRight.frame)
head.frame = bounds
head.path = head_path(head.frame)
snout.frame = bounds
snout.path = snout_path(snout.frame)
nostrilLeft.frame = bounds
nostrilLeft.path = nostrilLeft_path(nostrilLeft.frame)
nostrilRight.frame = bounds
nostrilRight.path = nostrilRight_path(nostrilRight.frame)
eyeLeft.frame = bounds
eyeLeft.path = eyeLeft_path(eyeLeft.frame)
eyeBallLeft.frame = bounds
eyeBallLeft.path = eyeBallLeft_path(eyeBallLeft.frame)
eyeRight.frame = bounds
eyeRight.path = eyeRight_path(eyeRight.frame)
eyeBallRight.frame = bounds
eyeBallRight.path = eyeBallRight_path(eyeBallRight.frame)
}
after adding the following to some UIView
override func layoutSubviews() {
moo(self.bounds)
}
you should see

Swift
100.0%
Sketch plugin to generate ios view code
exports your views as UIBezierPath as swift code so you'll have something like
let path = UIBezierPath()
path.moveToPoint(...)
...
It's very annoying to draw in ios in code. But it's annoying to draw in sketch and export it as a picture because you can no longer use the CGRect dimensions from ios. You're stuck with whatever dimensions you picked in sketch.
This will generate a bunch of swift functions, with 1 main function which takes in a CGRect so you can put it in layoutSubviews. All your shapes will be relative to how you depict them in sketch and the CGRect. Also you can edit the code and add your own transformations or animations, instead of having to create a ton of assets and load them dynamically.
For instance, if in sketch you offset your creation 20px from the left, and your arboard is 200px in width. Then at runtime of the ios application your creation will be offset 20*(width/200) where width is the width of the ios CGRect at runtime. This of course works with y offset, width, and height.
When you run the plugin it puts the generated code into your artboard, so if you have a very complex shape (or groups of shapes) pasting the code might be slow or even crash sketch. If it is complex and hasn't crashed, it might take minutes (spinning beachball) but it will work.

lazy var outline: CAShapeLayer = {
let l = CAShapeLayer()
l.lineWidth = 28
l.strokeColor = UIColor(hue: 0, saturation: 0, brightness: 1, alpha: 1).CGColor
l.fillColor = UIColor(hue: 0, saturation: 0, brightness: 1, alpha: 1).CGColor
self.layer.addSublayer(l)
return l
}()
...
func moo(bounds: CGRect) {
outline.frame = bounds
outline.path = outline_path(outline.frame)
body.frame = bounds
body.path = body_path(body.frame)
spot2.frame = bounds
spot2.path = spot2_path(spot2.frame)
spot.frame = bounds
spot.path = spot_path(spot.frame)
armLeft.frame = bounds
armLeft.path = armLeft_path(armLeft.frame)
armRight.frame = bounds
armRight.path = armRight_path(armRight.frame)
head.frame = bounds
head.path = head_path(head.frame)
snout.frame = bounds
snout.path = snout_path(snout.frame)
nostrilLeft.frame = bounds
nostrilLeft.path = nostrilLeft_path(nostrilLeft.frame)
nostrilRight.frame = bounds
nostrilRight.path = nostrilRight_path(nostrilRight.frame)
eyeLeft.frame = bounds
eyeLeft.path = eyeLeft_path(eyeLeft.frame)
eyeBallLeft.frame = bounds
eyeBallLeft.path = eyeBallLeft_path(eyeBallLeft.frame)
eyeRight.frame = bounds
eyeRight.path = eyeRight_path(eyeRight.frame)
eyeBallRight.frame = bounds
eyeBallRight.path = eyeBallRight_path(eyeBallRight.frame)
}
after adding the following to some UIView
override func layoutSubviews() {
moo(self.bounds)
}
you should see

Swift
100.0%