Skip to main content

Simple Ways to Customize NSSavePanel

·1 min

Cocoa provides the NSSavePanel class to open a save panel when the user wants to save a document. Save panels are initially configured for saving. The default button’s name is Save, and the panel’s title is also Save.

Suppose your application exports documents to various file formats. Exporting is similar to saving so you would open a save panel. When exporting you would like the panel title and the default button’s name to be Export instead of Save. How do you make these changes?

NSSavePanel provides properties to customize the various fields in the panel. The properties you are most likely to change are prompt, title, and nameFieldLabel.

prompt #

The prompt property stores the default button’s text. To change the button text from Save to Export, add the following Swift code:

let savePanel = NSSavePanel()
savePanel.prompt = "Export"

title #

The title property stores the name of the panel title. To change the title to Export, add the following Swift code:

savePanel.title = "Export"

nameFieldLabel #

The nameFieldLabel stores the label for the text field where the user enters the file name. To change the label from Save As: to Export As:, add the following Swift code:

savePanel.nameFieldLabel = "Export As:"