【发布时间】:2013-01-31 00:27:51
【问题描述】:
我正在尝试显示带有附件视图的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 组件吗?
谢谢!
【问题讨论】:
-
这对我来说似乎是一个错误。我可以更改字体,但不能更改大小。
-
对我来说也一样。更改颜色也很有效。
标签: objective-c font-size nsalert