我正在尝试显示带有附件视图的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 documentation说“信息性文本(使用小型系统字体)”,所以我使用的是[NSFont smallSystemFontSize]
,但它无法正确呈现(see):
任何提示?我应该创建自己的NSAlert
组件吗?
谢谢!
答案 0 :(得分:1)
您是否尝试过为textView创建IBOutlet并将其用作NSAlert的附件视图?