它需要一个棘手的实现。这是一个。您可以在应用程序的标签栏上添加按钮。它很棘手,但它有效。
为此,您必须将UITabBarController
.
像这样的东西
BaseViewController.h
@interface BaseViewController : UITabBarController
{
}
// Create custom UIButtons and add it to the tab bar
-(void) addButtons;
@end
BaseViewController.m
#import "BaseViewController.h"
#import "AppDelegate.h"
@implementation BaseViewController
// Create custom UIButtons and add it to the tab bar
-(void) addButtons
{
UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame: CGRectMake(20, 0, 330, 60)];
[backgroundImage setImage: [UIImage imageNamed: @"bottom.png"]];
[backgroundImage setCenter: self.tabBar.center];
[self.view addSubview: backgroundImage];
[backgroundImage release];
UIButton *firstTabbarButton = [UIButton buttonWithType: UIButtonTypeCustom];
firstTabbarButton.frame = CGRectMake(20.0, 52.0, 68, 49);
[firstTabbarButton setBackgroundImage:[UIImage imageNamed: @"home_normal.png"] forState:UIControlStateNormal];
[firstTabbarButton setBackgroundImage:[UIImage imageNamed: @"home_normal.png"] forState:UIControlStateHighlighted];
[firstTabbarButton setBackgroundImage:[UIImage imageNamed: @"home.png"] forState:UIControlStateSelected];
[firstTabbarButton addTarget: self action: @selector(goButtonClicked:) forControlEvents: UIControlEventTouchUpInside];
[firstTabbarButton setCenter: CGPointMake(33, self.tabBar.center.y)];
[firstTabbarButton setTag: 1000];
[firstTabbarButton setAdjustsImageWhenHighlighted: NO];
[self.view addSubview: firstTabbarButton];
UIButton *secondTabbarButton = [UIButton buttonWithType: UIButtonTypeCustom];
secondTabbarButton.frame = CGRectMake(20.0, 52.0, 68, 49);
[secondTabbarButton setBackgroundImage:[UIImage imageNamed: @"lab_normal.png"] forState:UIControlStateNormal];
[secondTabbarButton setBackgroundImage:[UIImage imageNamed: @"lab_normal.png"] forState:UIControlStateHighlighted];
[secondTabbarButton setBackgroundImage:[UIImage imageNamed: @"lab_hover.png"] forState:UIControlStateSelected];
[secondTabbarButton addTarget: self action: @selector(goButtonClicked:) forControlEvents: UIControlEventTouchUpInside];
[secondTabbarButton setCenter: CGPointMake(96, self.tabBar.center.y)];
[secondTabbarButton setTag: 1001];
[secondTabbarButton setAdjustsImageWhenHighlighted: NO];
[self.view addSubview: secondTabbarButton];
UIButton *thirdTabbarButton = [UIButton buttonWithType: UIButtonTypeCustom];
thirdTabbarButton.frame = CGRectMake(20.0, 52.0, 68, 49);
[thirdTabbarButton setBackgroundImage:[UIImage imageNamed: @"others.png"] forState:UIControlStateNormal];
[thirdTabbarButton setBackgroundImage:[UIImage imageNamed: @"others.png"] forState:UIControlStateHighlighted];
[thirdTabbarButton setBackgroundImage:[UIImage imageNamed: @"others_hover.png"] forState:UIControlStateSelected];
[thirdTabbarButton addTarget: self action: @selector(goButtonClicked:) forControlEvents: UIControlEventTouchUpInside];
[thirdTabbarButton setCenter: CGPointMake(287, self.tabBar.center.y)];
[thirdTabbarButton setTag: 1004];
[thirdTabbarButton setAdjustsImageWhenHighlighted: NO];
[self.view addSubview: thirdTabbarButton];
UIButton *forthTabbarButton = [UIButton buttonWithType: UIButtonTypeCustom];
forthTabbarButton.frame = CGRectMake(20.0, 52.0, 68, 49);
[forthTabbarButton setBackgroundImage:[UIImage imageNamed: @"history_normal.png"] forState:UIControlStateNormal];
[forthTabbarButton setBackgroundImage:[UIImage imageNamed: @"history_normal.png"] forState:UIControlStateHighlighted];
[forthTabbarButton setBackgroundImage:[UIImage imageNamed: @"history.png"] forState:UIControlStateSelected];
[forthTabbarButton addTarget: self action: @selector(goButtonClicked:) forControlEvents: UIControlEventTouchUpInside];
[forthTabbarButton setCenter: CGPointMake(223, self.tabBar.center.y)];
[forthTabbarButton setAdjustsImageWhenHighlighted: NO];
[forthTabbarButton setTag: 1003];
[self.view addSubview: forthTabbarButton];
UIImage *centerImage = [UIImage imageNamed:@"go_btn.png"];
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 52.0, 62, 62);
[button setTag: 1002];
[button setBackgroundImage:centerImage forState:UIControlStateNormal];
[button setBackgroundImage:highlightImage forState:UIControlStateSelected];
[button addTarget: self action: @selector(goButtonClicked:) forControlEvents: UIControlEventTouchUpInside];
CGFloat heightDifference = button.frame.size.height - self.tabBar.frame.size.height;
if (heightDifference < 0)
button.center = self.tabBar.center;
else
{
CGPoint center = self.tabBar.center;
center.y = center.y - heightDifference/2.0;
button.center = center;
}
[self.view addSubview:button];
}
@end
这将起作用。但请注意应用商店提交指南。尝试这个。