【发布时间】:2020-02-25 10:56:21
【问题描述】:
我正在尝试创建一个带有状态栏项目的 macOS 应用程序,该项目使用 PDF 而不是 PNG 图像,但是当我使用该图像时,它被过度缩放并且整个状态项目都是黑色的。我找不到缩放图像以使其适合其余 mac 状态栏项目的方法。
图标
-
Font Awesome
- (我无法附上 pdf,因此您需要手动转换)
资产.xcassets
AppDelegate.swift
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
let statusItem = NSStatusBar.system.statusItem(withLength:NSStatusItem.squareLength)
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
if let button = statusItem.button {
button.image = NSImage(named:NSImage.Name("status-logo"))
button.action = #selector(printQuote(_:))
}
}
@objc func printQuote(_ sender: Any?) {
let quoteText = "Never put off until tomorrow what you can do the day after tomorrow."
let quoteAuthor = "Mark Twain"
print("\(quoteText) — \(quoteAuthor)")
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
}
期待
现实
【问题讨论】:
标签: swift macos statusbar appkit