Iphone tabbar问题中的自定义按钮
我有一个TabBarController应用程序 此代码位于didFinishingLaunching方法中:Iphone tabbar问题中的自定义按钮,iphone,button,tabbar,Iphone,Button,Tabbar,我有一个TabBarController应用程序 此代码位于didFinishingLaunching方法中: UIImage *buttonImage = [UIImage imageNamed:@"post-button2.png"]; UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom]; NSLog(@"Button size: %f, %f", buttonImage.size.width, buttonIm
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];
但我不确定这是否正确
Ty.要设置选项卡的图像,需要设置与该选项卡关联的viewcontroller的tabBarItem 有关如何使用自定义图像创建一个,请参见UITABBARIEM ref 因此,可以使用自定义图像创建UITabBarItem对象,然后将其作为选项卡的viewcontroller的tabBarItem属性
然后,UITabBarController将设法将图像放置在正确的位置 它不是选项卡栏项目,而是选项卡栏上的自定义按钮。
CGPoint center = tabBarController.tabBar.center;
center.x = 160.00;
center.y = 455.50;
button.center = center;