UIToolBarのインスタンスを作成して、UIWindowのインスタンスに追加します。ツールバーへのボタン配置は、UIBarButtonItemのインスタンス作成してUIToolBarのitemsに追加することで実現できます。ボタンの種類は、UIBarButtonItemのinitWithBarButtonSystemItemに指定します。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
// ツールバーの作成
CGRect toolBarFrame = [UIScreen mainScreen].applicationFrame;
toolBarFrame.size.height = 44;
UIToolbar* toolBar = [[[UIToolbar alloc] initWithFrame:toolBarFrame] autorelease];
// ボタンの作成とツールバーへの配置
UIBarButtonItem* doneButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(done)]
autorelease];
toolBar.items = [NSArray arrayWithObject:doneButtonItem];
// ツールバーをwindowに追加
[self.window addSubview:toolBar];
[self.window makeKeyAndVisible];
return YES;
}
- (void)done{
}
実行結果は上の図の通りになります。ただ、ステータスバーとツールバーの隙間に違和感を感じます。違和感を無くすには、UIViewControllerでツールバーを作成するように構成を変える必要があるかもしれないです。

0 件のコメント:
コメントを投稿