Sonoma Issue on NSMenuItem keyEquivalent value

I want to add an keyEquivalent to NSMenuItem with font “Kanit-Light”. Till now it was working fine, But in Sonoma OS there is an issue that in the keyEquivalent the KeyEquivalentModifierMask (command symbol) is not aligned properly. It looks proper only when the system font is used for NSMenuItem. How can I solve this issue?

This is how it looks in Sonoma OS for Quit keyEquivalent

The code I have used is

let paraStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
paraStyle.lineBreakMode = .byTruncatingTail
    
var titleAttributes: [NSAttributedString.Key : Any]
titleAttributes = [.font:NSFont.settingsLightFont(withSize:14.0),.paragraphStyle:paraStyle]

quitMenuItem.attributedTitle = NSMutableAttributedString(attributedString: NSAttributedString(string: NSLocalizedString("Quit", comment: ""), attributes: titleAttributes))

Here for the keyEquivalent of the menu item, I have specified the value in the nib file

  • Unrelated but creating an NSMutableAttributedString from an attributed string which is not going to be mutated is redundant.

    – 

  • Here in the above code, if I use SystemFont with same font size then the issue gets solved. But I want to use the font “Kanit-Light” with size 14. The implementation looks fine as it was working in all other macOS. I face this issue with the recent Sonoma OS. Not sure if it’s apple related issue.

    – 

Leave a Comment