You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+50-54
Original file line number
Diff line number
Diff line change
@@ -3,34 +3,32 @@ iosViews
3
3
4
4
Sketch plugin to generate ios view code
5
5
6
-
###export_as_cgContext.sketchplugin
7
-
exports your views as CGContext as swift code
6
+
###pathExporter.sketchplugin (finally fixed)
7
+
exports your views as UIBezierPath as swift code
8
8
so you'll have something like
9
9
10
-
CGContextMoveToPoint(...)
11
-
CGContextAddCurveToPoint(...)
10
+
let path = UIBezierPath()
11
+
path.moveToPoint(...)
12
12
...
13
13
14
14
####Why?
15
15
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.
16
16
17
-
This will generate a bunch of swift functions, with 1 main function which takes in a CGRect so you can put it in drawRect. 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.
17
+
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.
18
18
19
19
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.
20
20
21
21
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.
22
22
23
-
Once I figure out how to make sketch save it to a file and NOT crash sketch, I'll do that and it should work much better.
24
23
25
24
####How does it work?
26
25
1. create an artboard (let's say iphone sized)
27
26
1. create some shape you want that you'd have to do in code otherwise
28
27
1. select the artboard (make sure it's only the artboard, this is very important)
29
28
1. SAVE, because sketch might might crash if you have weirdly intercepting paths in your shape (flatten them, and try to simplify them)
30
-
1. run the export_as_cgContext plugin
29
+
1. run the pathExporter.sketchplugin
31
30
- anything hidden will be ignored
32
-
- you will get code where everything is relative to the selection (artboard in this case)
33
-
- for each group in the selection, the plugin will generate a swift function named after the group (make sure these are unique)
31
+
- you will get code where everything is relative to the artboard
34
32
- NOTE: for complex shapes the export might be slow (take minutes)
35
33
36
34
####Unfortunatelly this doesn't work with:
@@ -45,8 +43,7 @@ Once I figure out how to make sketch save it to a file and NOT crash sketch, I'l
45
43
1. shadows, inner shadows, blurs, reflections are ignored
46
44
1. character spacing, line height, paragraph spacing are ignored
47
45
1. justified alignment is ignored
48
-
1. text decoration and list types are ignored
49
-
1. text weight is ignored
46
+
1. text layers are ignored
50
47
1. typeface might be iffy (I've only tested Helvetica Neue, and that's what ios defaults to if it can't find your typeface)
51
48
1. even/odd setting on fill is ignored (it uses whatever ios uses, I don't know if it's even/odd or non zero by default)
52
49
1. all border settings (ends, joints, start arrow, end arrow, dash, gap) are ignored
@@ -55,64 +52,63 @@ Once I figure out how to make sketch save it to a file and NOT crash sketch, I'l
55
52
- fix a lot of the things that don't work
56
53
- settle on a good shortcut
57
54
- add this to sketch toolbox
58
-
- make it export to a file, rather than cliboard (which is currently makes the pasting teeeerribly slow)
55
+
- make it export to a file, rather than cliboard (which is currently makes the pasting teeeerribly slow if you're pasting into xcode)
0 commit comments