[英]Tab Bar with Large Icons
I am wondering if there is a way to accomplish a tab bar with only large icons, I have attached an image below for reference. 我想知道是否有一种方法可以仅使用大图标来完成选项卡栏,我在下面附加了图像以供参考。 I am not interested in creating my own tab bar controller, and managing the view controllers myself.
我对创建自己的标签栏控制器以及自己管理视图控制器不感兴趣。
Here is my solution, i created a class which is a subclass of UITabBarController
. 这是我的解决方案,我创建了一个类,它是
UITabBarController
的子类。
CustomTabBarController.h CustomTabBarController.h
@interface CustomTabBarController : UITabBarController<UITabBarControllerDelegate>
@property (strong, nonatomic) IBOutlet UITabBar *tabBar;
@end
CustomTabBarController.m 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;
}
It's working for me,and i got no problem. 它为我工作,我没问题。 Hope, it helps.
希望能帮助到你。
To add to @limon's answer, if you want to change the height of the custom UITabBar, I found from another SO answer, sorry do not remember web link reference, the following code did the trick and locked it at the bottom as well, where I found with @limon's code the UITabBar was not position flush at bottom out of the box with his code: 要添加到@limon的答案中,如果您想更改自定义UITabBar的高度,我从另一个SO答案中找到了,抱歉,不记得Web链接参考了,下面的代码起到了作用并将其锁定在底部,在哪里我用@limon的代码发现UITabBar的位置与他的代码不在盒子底部齐平:
override func viewWillLayoutSubviews() {
//UITabBar Height
var tabFrame: CGRect = self.tabBar.frame
tabFrame.size.height = 75
tabFrame.origin.y = self.view.frame.size.height - 75
self.tabBar.frame = tabFrame
}
Obviously you want to remove the similar code from limon's answer or maybe move his entire code snippet to viewWillLayoutSubviews
I didn't try that, I called his code in my viewDidLoad
显然,您想从limon的答案中删除类似的代码,或者也许将其整个代码段移至
viewWillLayoutSubviews
我没有尝试过,我在viewDidLoad
调用了他的代码
The max size for the image in a tab bar on an iPhone 5/iPhone 4 is 96 x 64 so you are somewhat limited there without rolling your own. iPhone 5 / iPhone 4的选项卡栏中图像的最大尺寸为96 x 64,因此您在此处有限度而不会自行滚动。 Though in your example image those may fit in the constraints.
尽管在您的示例图像中,这些可能适合约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.