0
我有一個TabBarController應用程序。tabbar問題中的自定義按鈕
該代碼在didFinishingLaunching方法:
UIImage *buttonImage = [UIImage imageNamed:@"post-button2.png"];
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
NSLog(@"Button size: %f, %f", buttonImage.size.width, buttonImage.size.height);
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
CGFloat heightDifference = buttonImage.size.height - self.tabBarController.tabBar.frame.size.height;
NSLog(@"self.tabBarController.tabBar.frame.size.height: %f", self.tabBarController.tabBar.frame.size.height);
NSLog(@"heightDifference: %f", heightDifference);
NSLog(@"%Tabbar: %f, %f", tabBarController.tabBar.center.x, tabBarController.tabBar.center.y);
if (heightDifference < 0)
button.center = tabBarController.tabBar.center;
else {
CGPoint center = self.tabBarController.tabBar.center;
center.y = center.y - heightDifference/2.0;
button.center = tabBarController.tabBar.center;
}
NSLog(@"%Button: %f, %f", button.center.y, button.center.x);
[tabBarController.view addSubview:button];
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
的輸出是:
問題在哪裏?我可以用硬編碼解決:
CGPoint center = tabBarController.tabBar.center;
center.x = 160.00;
center.y = 455.50;
button.center = center;
但我不確定這是否正確。
Ty。
它不是一個tabbar項目,它是tabbar上的一個自定義按鈕。 – 2011-01-22 20:37:45