0

我正在尝试显示NSAlert带有附件视图的链接,以便可以在信息性消息下方的文本块中显示链接。这是我的代码。

#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 文档说“信息性文本(使用小型系统字体)”,所以我正在使用[NSFont smallSystemFontSize]但它不能正确呈现(请参阅):

  • 它没有对齐
  • 它没有使用小字体(我尝试过使用其他值,例如 1.0),但似乎忽略了字体属性。

有什么提示吗?我应该创建自己的NSAlert组件吗?

谢谢!

4

1 回答 1

1

您是否尝试过为 textView 创建一个 IBOutlet 并将其用作 NSAlert 的附件视图?

于 2013-02-15T09:31:50.527 回答