Swiftpack.co - francisfeng/SymbolPicker as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by francisfeng.
francisfeng/SymbolPicker 0.3.0
A SF Symbols picker for Mac apps. Built with AppKit.
⭐️ 4
🕓 2 weeks ago
macOS
.package(url: "https://github.com/francisfeng/SymbolPicker.git", from: "0.3.0")

Symbol Picker

A SF Symbols picker for Mac apps. Built with AppKit.

Compatibility

  • macOS 11.0+

Install

Add https://github.com/francisfeng/SymbolPicker in the “Swift Package Manager” tab in Xcode.

Usage

screenshot of Symbol Picker

  1. AppKit

// in your NSViewController subclass
import SymbolPicker

@objc func pickIcon(_ sender: NSMenuItem) {
  if let windowController = SymbolPicker.windowController(
      symbol: collection.symbol,
      color: collection.color ?? .labelColor,
      delegate: self,
      title: collection.name),
     let iconSheet = windowController.window {
    
    // You need to persist this windowController in your app.
    symbolPickerWindowController = windowController
    
    window.beginSheet(iconSheet) {
      _ in
      self.symbolPickerWindowController = nil
    }
  }
}

extension ViewController: SymbolPickerDelegate {
  func symbolPicker(_ symbol: String, color: NSColor?) {
  
  }
}
  1. SwiftUI

I haven't try it with SwiftUI yet. Any contributions will be welcome.

Improve User Experience

  1. This symbol picker can't be presented like a modal dialog as it also contains a toolbar. To mimic the modal dialog experience, the window is not movable or resizable. You may also want to implement click-outside to dismiss in your app. You can do this by overriding func mouseDown(with: NSEvent) in your NSWindowController subclass.
override func mouseDown(with event: NSEvent) {
  super.mouseDown(with: event)
  if let sheetwindow = window?.attachedSheet {
    window?.endSheet(sheetwindow)
  }
}

Lisense

MIT

GitHub

link
Stars: 4
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics