如何在Mac OS的菜单栏应用程序中显示两行文本 [英] How to show two row of text in a menu bar app in mac os
问题描述
您能告诉我如何在osx上制作一个应用程序(快速3),在菜单栏中仅显示两行文本(在扩展坞上没有图标),如下图所示?或至少如何在菜单栏上显示文本?
can you explain to me how to make an app on osx (with swift 3) showing only (without icon on the dock) two row of text in the menu bar like in the picture below ? or at least how to show text on the menu bar ?
OSX菜单栏图片:
OSX Menu bar picture:
PS:我是osx应用开发人员的新手,所以请不要犹豫;)
PS: I am new on osx app dev so don't hesitate to be very verbose ;)
推荐答案
- 这种应用程序称为菜单栏应用程序或menulet.
- 无坞站外观由
Info.plist
中的键 - 使用自定义的
NSView
- 将视图分配给
NSStatusItem
实例的view
属性. - 在
drawRect
中绘制文本
- This kind of app is called menu bar app or menulet.
- The dockless appearance is set by the key
LSUIElement
(1) inInfo.plist
- Use a custom
NSView
- Assign the view to the
view
property of theNSStatusItem
instance. - Draw the text in
drawRect
LSUIElement
(1)设置.重要提示:使用自定义视图需要实现所有方法来处理突出显示,鼠标单击和 NSMenu
委托.
Important: Using a custom view requires to implement all methods to handle the highlighting, mouse clicks and NSMenu
delegate.
这是文章的实现方法,它在Objective-C中,但这可能是一个起点:
将自定义视图添加到NSStatusItem
Here is an article how to do it, it's in Objective-C but this might be a starting point:
Adding a Custom View to an NSStatusItem
这篇关于如何在Mac OS的菜单栏应用程序中显示两行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!