2013-02-15 25 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

相關問題