简体   繁体   中英

Cocoa NSStatusItem image – opaque background

I'm making a tiny menu bar app that shows the current iTunes song in the status bar. It works great, except for the fact that in dark mode, black areas of the album art show up the same color as the (transparent) menu bar background:

透明状态项-BG

Is there any way to make this be an opaque black background, instead?


On the white background, it makes white be the white transparent background, but black is a nice, deep black (overall I find this less annoying):

透明状态项-BG-白

Currently, I'm just using [statusItem setImage:artworkImage] to set the image.

For some reason, adding a transparent NSView as a subview of the status item's button works wonderfully:

let subview = NSView.init(frame: statusItem!.button!.frame)
statusItem?.button?.addSubview(subview)

Now, I still have no idea why it works.

Edit: This works up to OS X v10.13 High Sierra, but does not work on v10.14 Mojave . It's back to transparency.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM