Skip to content

Latest commit

 

History

History
32 lines (20 loc) · 977 Bytes

README.md

File metadata and controls

32 lines (20 loc) · 977 Bytes

NSFontPanelDemo

Sample macOS Cocoa app Xcode project demonstrating how to use NSFontPanel to let user change font.

demo

The key is to implement the changeFont(_ sender: Any?) function in your view controller, or in the NSWindowController, AppDelegate that is placed above in the Responder Chain.

override func changeFont(_ sender: Any?) {

  // the sender is a font manager
  guard let fontManager = sender as? NSFontManager else {
    return
  }
	
  // the newly selected font
  /*
  	you can actually pass in any font into the .convert() function and it
  	will return the selected font from the panel, lol
  */
	
//  let newFont = fontManager.convert(NSFont.systemFont(ofSize: 13.0))
  let newFont = fontManager.convert(self.font)
  yourLabel.font = newFont
}