LoginSignup
3
1

More than 1 year has passed since last update.

macOSアプリのメニューバーアイコンのデザイン

Last updated at Posted at 2022-03-05

概要

  • 以下のようにメニューバーアイコンを作って表示してみる。
image
  • HIGによるとメニューバーアイコンにはテンプレートイメージを使う。
  • つまり黒と透明度のみでデザインされた画像とすることが推奨。

    Use a template image to represent your menu bar extra. A template image discards color information and uses a mask to produce the appearance you see onscreen. Template images automatically adapt to the user’s appearance settings, so they look good on both dark and light menu bars, and when your menu bar extra is selected.

    • ライト/ダークモードで視認しやすい色で表示されるのが嬉しい。
    • Appleのものを見ると基本テンプレート画像なのでそれに調和させる。(Siriは多分例外)
    • Providing Images for Different Appearances
  • 画像の高さは28pxとする。(公式な記載がないので私の感覚)

GitHub

イラストレータでの画像の作成/出力

  • 塗りには黒のみを使用。
  • 不透明度の変更による表現は可能。
image
  • 1x,2x,3x用にそれぞれ14,28,42pxで出力。
image

Xcode

Assetsの設定

  • Render AsTemplate Imageを選択。
image

実装

  • メニューバーにアイコンを表示するだけの実装。
  • AppDelegateでStatusBarIconControllerのインスタンスをプロパティと持たせておく。
    • 実際の運用ではNotificationでアイコンを変更したいことがあるので。
import AppKit

class StatusBarIconController: NSObject {
    
    // MARK: - Properties
    
    private let systemStatusItem: NSStatusItem

    private var menubarIconStandard: NSImage {
        return NSImage(named:NSImage.Name("MenubarIcon"))!
    }
    
    // MARK: - LifeCycle
    
    override init() {
        systemStatusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
        super.init()
        systemStatusItem.button?.image = menubarIconStandard
    }
}

テンプレート画像の反転した状態を確認

  • Accfessibility>DisplayからReduce trasparencyでテンプレート画像の表示を変更でき、ライト/ダークモードの時の確認がそれぞれできる。
image image image
3
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1