Instance Property

accessoryView

The alert’s accessory view.

Declaration

@property(strong) NSView *accessoryView;

Discussion

The NSAlert class places the accessory view between the informative text or suppression checkbox (if present) and the response buttons. Before you change the location of the accessory view, first call the layout method.

alertStyle shows an example of adding an accessory view to an alert. buttons shows the alert generated.

Listing 1

Adding an accessory view to an alert

NSTextView *accessory = [[NSTextView alloc] initWithFrame:NSMakeRect(0,0,200,15)];
NSFont *font = [NSFont systemFontOfSize:[NSFont systemFontSize]];
NSDictionary *textAttributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
[accessory insertText:[[NSAttributedString alloc] initWithString:@"Text in accessory view."
                                                      attributes:textAttributes]];
[accessory setEditable:NO];
[accessory setDrawsBackground:NO];
 
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = @"Message text.";
[alert setInformativeText:@"Informative text."];
alert.accessoryView = accessory;
[alert runModal];
[alert release];
Figure 1

Alert dialog with an accessory view

See Also

Configuring Alerts

- layout

Specifies that the alert must do immediate layout instead of lazily just before display.

alertStyle

Indicates the alert’s severity level.

showsHelp

Specifies whether the alert has a help button.

helpAnchor

The alert’s HTML help anchor.

delegate

The alert’s delegate.