|
「About」パネルのプロパティリスト値情報プロパティリストファイルには、バンドルされている実行可能ファイルの基本的な設定情報が含まれています。ほとんどのバンドルには、この種類のファイル(通常、ファイル名は
表1:次のキー文字列は、オプションディクショナリで使用できるキーです。
バージョン表示フォーマット「About」パネルのバージョン文字列を作成するアルゴリズムは、マーケティングバージョン(MV)およびビルドバージョン(BV)があるかどうかに応じて、次のように「About」パネルに表示します。 Version MV (BV) Version MV Version BV 上記の表の繰り返しになりますが、MVはディクショナリの Tiger以降のシステムでは、単語「Version」を追加します。Tiger以前のシステムでは、「v」をその代わりとして使用しています。 'orderFrontStandardAboutPanelWithOptions'を使用した「About」パネルこの例では、オプションのディクショナリを用いて標準「About」パネルを使用する方法を示します。クレジットセクションを実装するかどうか(すなわち、使用しているプロジェクトに「 リスト1:'orderFrontStandardAboutPanelWithOptions'を使用したサンプル
#import "Controller.h"
@implementation Controller
- (IBAction)openAboutPanel:(id)sender
{
NSDictionary *options;
NSImage *img;
img = [NSImage imageNamed: @"Picture 1"];
options = [NSDictionary dictionaryWithObjectsAndKeys:
@"1.1", @"Version",
@"Super App", @"ApplicationName",
img, @"ApplicationIcon",
@"Copyright 2005-2006, My Great Company", @"Copyright",
@"Super App v1.1", @"ApplicationVersion",
nil];
[[NSApplication sharedApplication] orderFrontStandardAboutPanelWithOptions:options];
}
@end
図1:リスト1による「About」パネルのサンプル
独自の'NSView'を使用した「About」パネル独自の「About」パネルを作成するには、使用しているアプリケーションのバンドル情報を直接読み、自分のパネルやウインドウもしくは リスト2:独自のNSViewで「About」パネルの使用法を示すサンプル
@interface AboutView : NSView
{}
@end
@implementation AboutView
-(id)infoValueForKey:(NSString*)key
{
if ([[[NSBundle mainBundle] localizedInfoDictionary] objectForKey:key])
return [[[NSBundle mainBundle] localizedInfoDictionary] objectForKey:key];
return [[[NSBundle mainBundle] infoDictionary] objectForKey:key];
}
- (void)drawRect:(NSRect)rect
{
[super drawRect: rect];
// 背景を白に描画する
[[NSColor whiteColor] set];
[NSBezierPath fillRect:rect];
// NSBundle情報を表示する
NSString* nameStr = [self infoValueForKey:@"CFBundleName"];
NSTextField* field = [self viewWithTag: 1];
[field setStringValue: nameStr];
NSString* versionStr = [self infoValueForKey:@"CFBundleVersion"];
field = [self viewWithTag: 2];
[field setStringValue: versionStr];
NSString* copyrightStr = [self infoValueForKey:@"NSHumanReadableCopyright"];
field = [self viewWithTag: 3];
[field setStringValue: copyrightStr];
// アプリケーションのアイコンを描画する
NSImage* iconImage = nil;
NSImageView* imageView = [self viewWithTag: 0];
NSString* iconFileStr = [self infoValueForKey:@"CFBundleIconFile"];
if ([iconFileStr length] > 0)
{
// アイコンの実体が存在する
iconImage = [NSImage imageNamed: iconFileStr];
}
else
{
// アプリケーションアイコンが定義されていないので、デフォルトのシステムアイコンを使用する
iconImage = [NSImage imageNamed: @"NSApplicationIcon"];
// もしくは
//NSString* appIconType = NSFileTypeForHFSTypeCode(kGenericApplicationIcon);
//iconImage = [[NSWorkspace sharedWorkspace] iconForFileType:appIconType];
}
[imageView setImage: iconImage];
}
@end
技術文書
ドキュメント改訂履歴
掲載日: 2007-01-22 | |||||||||||||||||||||||||||||||
|