我试图显示带有附件视图的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
组件吗?
谢谢!
这看起来像一个bug给我。我可以改变字体但不是大小。 – rdelmar 2013-02-15 04:10:32
同样适用于我。改变颜色也起作用。 – 2013-02-15 14:43:36