I'm trying to display an NSAlert
with an accessory view so I can show a link in a block of text below the informative message. Here is my code.
#import "AppDelegate.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSAlert *activateAlert = [NSAlert alertWithMessageText: @"Some message text"
defaultButton: @"OK"
alternateButton: nil
otherButton: nil
informativeTextWithFormat: @"Some informative text"];
NSTextView *accessory = [[NSTextView alloc] initWithFrame: NSMakeRect(0,0,300,15)];
NSFont *font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
NSDictionary *textAttributes = @{NSFontAttributeName: font};
[accessory insertText:[[NSAttributedString alloc] initWithString:@"Some text in an accessory view"
attributes: textAttributes]];
accessory.editable = NO;
accessory.drawsBackground = NO;
[accessory setAutomaticLinkDetectionEnabled: YES];
activateAlert.accessoryView = accessory;
[activateAlert beginSheetModalForWindow: self.window
modalDelegate: nil
didEndSelector: nil
contextInfo: nil];
}
@end
Apple documentation says "the informative text (which uses small system font)", so I'm using [NSFont smallSystemFontSize]
but it doesn't render properly (see):
- It's not aligned
- It's not using a small font size (I've tried using other values, like 1.0) but it seems the font attribute is ignored.
Any hints? Should I create my own NSAlert
component?
Thanks!