我想知道是否有一种方法可以仅使用大图标来完成选项卡栏,我在下面附加了图像以供参考。我对创建自己的标签栏控制器以及自己管理视图控制器不感兴趣。
最佳答案
这是我的解决方案,我创建了一个类,它是UITabBarController
的子类。
CustomTabBarController.h
@interface CustomTabBarController : UITabBarController<UITabBarControllerDelegate>
@property (strong, nonatomic) IBOutlet UITabBar *tabBar;
@end
CustomTabBarController.m
- (void)viewDidLoad
{
CGRect tabBarFrame = self.tabBar.frame ;
tabBarFrame.origin.y -= kOrigin;
tabBarFrame.size.height = kTabBarHeight;
self.tabBar.frame = tabBarFrame;
self.tabBarController.delegate = self;
/* Tab Bar Background */
UIImage *tabBarBackgroundImage = [UIImage imageNamed:@"tabBarBackgroundImage.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackgroundImage];
/* Tab Bar Item */
UIButton *surveyButton = [UIButton buttonWithType:UIButtonTypeCustom];
[surveyButton addTarget:self action:@selector(surveyButtonDidSelect) forControlEvents:UIControlEventTouchUpInside];
surveyButton.tag = surveyButtonTag;
[surveyButton setBackgroundImage:[UIImage imageNamed:@"someimage.png"] forState:UIControlStateNormal];
CGRect surveyButtonFrame = surveyButton.frame ;
surveyButtonFrame.origin.x = /*Proper value in your case */;
surveyButtonFrame.origin.y = /*Proper value in your case */;
surveyButtonFrame.size.height = /*Proper value in your case */ ;
surveyButtonFrame.size.width =/*Proper value in your case */;
surveyButton.frame = surveyButtonFrame;
[self.tabBar addSubview:surveyButton];
UIButton *statusButton = [UIButton buttonWithType:UIButtonTypeCustom];
statusButton.tag = statusButtonTag;
[statusButton addTarget:self action:@selector(statusButtonDidSelect) forControlEvents:UIControlEventTouchUpInside];
[statusButton setBackgroundImage:[UIImage imageNamed:@"someimage.png"] forState:UIControlStateNormal];
CGRect statusButtonFrame = statusButton.frame ;
statusButtonFrame.origin.x = /*Proper value in your case */;
statusButtonFrame.origin.y = /*Proper value in your case */;
statusButtonFrame.size.height = /*Proper value in your case */;
statusButtonFrame.size.width = /*Proper value in your case */;
statusButton.frame = statusButtonFrame;
[self.tabBar addSubview:statusButton];
}
-(void)surveyButtonDidSelect
{
self.selectedIndex = 0 ;
}
-(void)statusButtonDidSelect
{
self.selectedIndex = 1;
}
它为我工作,我没问题。
希望能帮助到你。
关于iphone - 带大图标的选项卡栏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16740824/