UITabBarのタブを画面の上部に配置する方法


UITabBarではTabは画面下部に表示される。Tabを上側に表示するためには以下のようにすればよい。
・TabBarを上に移動する
tabBarController.tabBar の位置を調整すればよい
・コンテンツ表示部を下に移動する
コンテンツを表示している部分のViewは公式ドキュメントに記載されていないので、どうにかこうにか頑張って見つけて、移動させる。非公開なオブジェクトを操作するのはルール違反なので、審査に落ちるかもしれません。自己責任でお願いします。

2013-02-16_1653

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1, *viewController2;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[MasterDetailFirstViewController alloc] initWithNibName:@"MasterDetailFirstViewController_iPhone" bundle:nil];
viewController2 = [[MasterDetailSecondViewController alloc] initWithNibName:@"MasterDetailSecondViewController_iPhone" bundle:nil];
} else {
viewController1 = [[MasterDetailFirstViewController alloc] initWithNibName:@"MasterDetailFirstViewController_iPad" bundle:nil];
viewController2 = [[MasterDetailSecondViewController alloc] initWithNibName:@"MasterDetailSecondViewController_iPad" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;

//ここから追記
//TabBarのサイズと、全体のサイズを取得
float t_hight = self.tabBarController.tabBar.frame.size.height;
float w_width = self.window.frame.size.width;
float w_height = self.window.frame.size.height;

//TabBarを移動
self.tabBarController.tabBar.frame = CGRectMake(0.0f, 20.0f, w_width, t_hight);

//コンテンツ表示部を移動
UIView * contentView = [[[self.tabBarController.tabBar superview] subviews] objectAtIndex:0];
contentView.frame = CGRectMake(0, t_hight, w_width, w_height - t_hight);
//ここまで追記

[self.window makeKeyAndVisible];
return YES;
}

Comments

comments

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です