Make first menuItem in MainMenu bold ?

I change the mainMenu loading a new MainMenu from xib.


I call the newMenu in place of existing one as follows:

        Bundle.main.loadNibNamed("newMainMenu", owner: self, topLevelObjects: nil)

I get the new menu.


But the First item (which usually holds the app name) is plain, I would need it bold.



Is that even possible with a menu title different from the app's name ?

I've tried whatever I could imagine without success.

Notably:

        let items = NSApplication.shared.mainMenu?.items
        let firstItem = items?[0]
        let subMenu = firstItem?.submenu
        subMenu?.title = "NewApplication " // Only this can change the menu title
        subMenu?.font = NSFont.boldSystemFont(ofSize: 0)


In fact, detailed situation is :

- original first item of mainmenu is "MyApp"

- new menu title in xib is "NewApplication"


If I just call

Bundle.main.loadNibNamed("newMainMenu", owner: self, topLevelObjects: nil)

I get the new menu (submenus are different), but title of the first remains "MyApp" and is bold


If I add:

        let items = NSApplication.shared.mainMenu?.items
        let firstItem = items?[0]
        let subMenu = firstItem?.submenu
        subMenu?.title = "NewApplication"

I get the new menu bar but title of first item remains MyApp.


However, if I change a bit adding a " " to the name

        let items = NSApplication.shared.mainMenu?.items
        let firstItem = items?[0]
        let subMenu = firstItem?.submenu
        subMenu?.title = "NewApplication "     // ADDED " " at the end, name is different

I get the new menu (submenus are different), title is now "NewApplication" but plain, not bold


I tried to add:

        subMenu?.font = NSFont.boldSystemFont(ofSize: 0)

No change, still plain


Also tried:

        var attributes = [NSAttributedString.Key: Any]()
        let boldFont = NSFont.boldSystemFont(ofSize: 0)
        attributes[NSAttributedString.Key.font] = boldFont
        firstItem?.attributedTitle = NSAttributedString(string: "NewApplication ", attributes: attributes)

With no result: still plain, not bold.


I come to the conclusion that when OSX recognizes the name of the app it turns title bold. Otherwise, cannot be bold, just as any other menu.

Only option would be to change the app name, which is a bit extreme solution.


Read this SO, no solution there either.

https://stackoverflow.com/questions/4965466/set-titles-of-items-in-my-apps-main-menu


Am I right ?

Answered by Claude31 in 395829022

Thanks.

HIG says "menu’s title includes your app name and is displayed in bold":

The app menu includes menu items that apply to your app as a whole, rather than a specific document or window. To help people quickly identify the active app, the menu’s title includes your app name and is displayed in bold.


But does not say anything if changing this menu title (it is possible as illustrated below).


The app menu includes menu items that apply to your app as a whole, rather than a specific document or window. To help people quickly identify the active app, the menu’s title includes your app name and is displayed in bold.The point is I have 2 mainMenu in xib

- the original, with the App name as 1st menu title 'AppName'

- a new one with a different name (just for testing purpose) as 1st menu title. 'ModifiedName'


In IB, both titles, AppName and ModifiedName are bold.


But when I call the newMainMenu

        Bundle.main.loadNibNamed("newMainMenu", owner: self, topLevelObjects: nil)

the title of first menu remains AppName and is bold: so it is not the one in its xib.


So, I try to set it manually to ModifiedName

        let items = NSApplication.shared.mainMenu?.items
        let firstItem = items?[0]
        let subMenu = firstItem?.submenu
        subMenu?.title = "ModifiedName"

I get ModifiedName as title of firstMenu, but no way to get it bold.


So, I could but don't want to change the app's name

>I come to the conclusion that


Right, DIY bolding in that example should not need to be done; the OS should do it on it's own. When I check via IB, the application name is already bolded...


See the HIGs https://developer.apple.com/design/human-interface-guidelines/macos/menus/menu-bar-menus/


About changing the app name...are you using a macro?


Just seems odd you'd need to do this manually, but you don't seem to be the only one that's seen it, so maybe a bug.

Make first menuItem in MainMenu bold ?
 
 
Q