项目作者: fumoboy007

项目描述 :
A preferences window that adheres to the macOS Human Interface Guidelines.
高级语言: Swift
项目地址: git://github.com/fumoboy007/DMPreferencesWindow.git
创建时间: 2019-01-03T03:35:43Z
项目社区:https://github.com/fumoboy007/DMPreferencesWindow

开源协议:MIT License

下载


DMPreferencesWindow

A preferences window suitable for a macOS app. Its user experience adheres to the macOS Human Interface Guidelines.

Requires Swift 5.3+. Tested on macOS 11. MIT license.

User Features

  • Toolbar for switching between preference panes.
  • Safari-like animation when switching between preference panes.
  • Automatic window title updates based on the selected preference pane.
  • Restores the last viewed preference pane.
  • Automatically hides the toolbar if there is only one preference pane.

Developer Features

  • Fully written in Swift. Higher confidence in code correctness.
  • Implement your preference panes using view controllers.
  • Use Auto Layout in your preference pane view controllers.
  • Optionally pre-select a preference pane before showing the preferences window (e.g. when linking to a preference pane).
  • Easy to develop a new interaction mechanism for selecting preference panes (e.g. segmented control instead of toolbar).
  • Easy localization.

Usage

  1. class GeneralPreferencePaneViewController: NSViewController, PreferencePane, ToolbarItemImageProvider {
  2. init() {
  3. // …
  4. title = NSLocalizedString("General",
  5. comment: "The title of the General preference pane.")
  6. }
  7. let preferencePaneIdentifier = PreferencePaneIdentifier(rawValue: "general")
  8. let toolbarItemImage = NSImage(named: NSImage.preferencesGeneralName)!
  9. }
  1. @NSApplicationMain
  2. class AppDelegate: NSObject, NSApplicationDelegate {
  3. private let preferencesWindowController: PreferencesWindowController = {
  4. let preferencePaneViewControllers: [NSViewController & PreferencePane & ToolbarItemImageProvider] = [
  5. GeneralPreferencePaneViewController(),
  6. // …
  7. ]
  8. return PreferencesWindowController(preferencePaneViewControllers: preferencePaneViewControllers)
  9. }()
  10. @IBAction
  11. private func showPreferencesWindow(_ sender: Any) {
  12. preferencesWindowController.showWindow(self)
  13. }
  14. }

Important: Ensure that each of your preference panes has an unambiguous and fixed width and height, explicitly via width/height constraints and/or implicitly via the constraints of the subviews.