インターフェイスビルダーを使用してタブバーコントローラーにボタンを追加することは可能ですか?
インターフェイスビルダーでこれを実行しようとしていますが、タブバーの上にボタンを追加するたびに、ボタンをタブバーの上に置くのではなく、画面の残りの部分をボタンで埋めます。
インスタグラムのカメラのようなもの。
インターフェイスビルダーを使用してタブバーコントローラーにボタンを追加することは可能ですか?
インターフェイスビルダーでこれを実行しようとしていますが、タブバーの上にボタンを追加するたびに、ボタンをタブバーの上に置くのではなく、画面の残りの部分をボタンで埋めます。
インスタグラムのカメラのようなもの。
これが私が問題を解決した方法です:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImage *buttonImage = [UIImage imageNamed:@"cameraTabBarItem.png"];
UIImage *highlightImage = [UIImage imageNamed:@"cameraTabBarItem.png"];
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
CGFloat heightDifference = buttonImage.size.height - self.tabBarController.tabBar.frame.size.height;
if (heightDifference < 0)
button.center = self.tabBarController.tabBar.center;
else
{
CGPoint center = self.tabBarController.tabBar.center;
center.y = center.y - heightDifference/2.0;
button.center = center;
}
[button addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
[self.tabBarController.view addSubview:button];
}
おそらく、ボタンを App Delegate のウィンドウのサブビューとして追加する必要があります。
[self.window addSubview:myButton];