My notes on using sketch to make and add vector graphics to xCode projects
TL;DR
Sketch.app -> export .pdf -> add to assets.xcasette
-> add to UIImage...
Instructions
- Figure out the size of the graphic you want to use: for instance 24x24
- Make a square in sketch that is
24x24
- Insert -> Artboard pick (set the artboard to
24x24
and set x/y to 0) - Click make exportable in the bottom right corner (set format to pdf, click export)
- XCode: click the
assets.xcasette
and Drag the .pdf file into the left sideview - Open the right sideview / attribute-inspector and set preserve vector to true, set scale to single scale
- Add the asset to code:
let image: UIImage = .init(imageLiteralResourceName: "nameOfResource")
- Add dark/light mode by adding apperance in the right sideview
Example:
let image: UIImage = .init(imageLiteralResourceName: "airbnb")
let rect = CGRect(origin: .zero, size: .init(width: 76, height: 76))
let imageView = UIImageView(frame: rect)
imageView.image = image
addSubview(imageView)
Note:
It’s also posible to use .svg
Via this framework (for iOS and macOS): https://github.com/eonist/SVGWrapper/tree/main