|
| 1 | +# Add Custom Symbols |
| 2 | + |
| 3 | +To create a new asset, follow the guide on [Apple's developer website](https://developer.apple.com/documentation/uikit/uiimage/creating_custom_symbol_images_for_your_app). |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Add the `.svg` you exported from `SF Symbols.app` to the `Symbols.xcassets` catalog. |
| 8 | + |
| 9 | +Also add a static property to the `Image` and `NSImage` extension like so: |
| 10 | + |
| 11 | +```swift |
| 12 | +// Image Extension |
| 13 | +static let your_symbol_name: Image = .init(symbol: "your_symbol_name") |
| 14 | + |
| 15 | +// NSImage Extension |
| 16 | +static let your_symbol_name: NSImage = .symbol(named: "your_symbol_name") |
| 17 | +``` |
| 18 | + |
| 19 | +> **Important:** Make sure your symbol looks great in every font weight. |
| 20 | +
|
| 21 | + |
| 22 | +## Tests |
| 23 | + |
| 24 | +Also include snapshot tests for each symbol for `Image` as well as `NSImage`: |
| 25 | + |
| 26 | +### NSImage: |
| 27 | + |
| 28 | +```swift |
| 29 | +// MARK: YOUR_SYMBOL_NAME |
| 30 | + |
| 31 | +func testCreateNSImageYourSymbolName() { |
| 32 | + let image = NSImage.your_symbol_name |
| 33 | + let view = NSImageView(image: image) |
| 34 | + view.appearance = .init(named: .aqua) |
| 35 | + assertSnapshot(matching: view, as: .image, record: record) |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +### Image: |
| 40 | + |
| 41 | +```swift |
| 42 | +// MARK: YOUR_SYMBOL_NAME |
| 43 | + |
| 44 | +func testCreateImageYourSymbolName() { |
| 45 | + let image = Image.your_symbol_name |
| 46 | + let view: NSView = NSHostingController(rootView: image).view |
| 47 | + view.appearance = .init(named: .aqua) |
| 48 | + assertSnapshot(matching: view, as: .image(size: view.intrinsicContentSize)) |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +## Variants |
| 53 | + |
| 54 | +Keep different variants of a symbol in the same parent folder and name them appropriately (see Apple's own symbols for reference). |
| 55 | + |
| 56 | +You might have a symbol called `lock` and one where the symbol is inside a square where you would call that file `lock.square`. Also keep in mind to also provide a `.fill` variant if appropriate (`lock.fill`, `lock.square.fill`) |
| 57 | + |
| 58 | +### Example of a `.fill` Variant |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +## Annotate the Symbol |
| 63 | + |
| 64 | +As of version 3 of `SF Symbols` it is possible to create `multi-color`, `hierarchical` and `palette` annotations inside the `SF Symbols.app`. Be sure to annotate it accordingly if appropriate. |
| 65 | + |
| 66 | + |
0 commit comments