2013-02-15 57 views
0

我试图显示带有附件视图的NSAlert,因此我可以在信息消息下方的文本块中显示链接。这是我的代码。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):

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

任何提示?我应该创建我自己的NSAlert组件吗?

谢谢!

+0

这看起来像一个bug给我。我可以改变字体但不是大小。 – rdelmar 2013-02-15 04:10:32

+0

同样适用于我。改变颜色也起作用。 – 2013-02-15 14:43:36

回答

1

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

+0

我试过你的解决方案,它的工作原理,所以我试图直接使用它的字体属性设置字体到NSTextView,现在它的作品...任何关于左侧的差距的想法? ([这里](http://d.pr/i/fVPW)) – 2013-02-15 13:48:56

+0

你试过玩textView的框架吗? – Shashank 2013-02-15 16:07:19

+0

是的,尝试了一个负面的,没有改变一件事... – 2013-02-22 20:20:01