UITabBarController的item间距能不能设置 


UITabBarController的每个item不设title的话,那个title还是会占据着最下面那一行的位置,该怎么去隐藏它让那个位置空出来





可以换一种方案,调整UIBarItem的imageInsets使图片居中 (我假设你真正想要的是让图片居中显示)


iOS UITabBarController tabbar 自定义 详解_#pragma



<code style="font-family: 'Source Code Pro', Consolas, Menlo, Monaco, 'Courier New', monospace; font-size: 1em; color: inherit; padding: 0px; white-space: inherit; background: none;"><span class="hljs-title" style="color: rgb(38, 139, 210);">[self.tabBarItem setImageInsets:UIEdgeInsetsMake(10, 0, -10, 0)]</span><span class="hljs-comment" style="color: rgb(147, 161, 161);">;</span>
</code>


UIEdgeInsetsMaketopbottom属性为相反数,

否则会发生点击item后拖动,item会发生形变。



1. //  
2. //  RootViewController.m  
3. //  test_storyBoard_ipad  
4. //  
5. //  Created by admin on 3/4/16.  
6. //  Copyright © 2016 jeffasd. All rights reserved.  
7. //  
8.   
9. #import "RootViewController.h" //父类 UITabbarController  
10.   
11. @interface RootViewController ()  
12.   
13. @end  
14.   
15. @implementation RootViewController  
16.   
17. - (void)viewDidLoad {  
18. super viewDidLoad];  
19.   
20.       
21. //    [self.tabBarItem setImageInsets:UIEdgeInsetsMake(10, 0, -10, 0)];  
22.       
23. //    [self.tabBarItem setImageInsets:UIEdgeInsetsMake(30, 0, -30, 0)];  
24.       
25. //    self.tabBar.items  
26.       
27. for (UITabBarItem *item in self.tabBar.items) {  
28.           
29. //        UIEdgeInsets insets = {top, left, bottom, right};  
30.           
31. //        [item setImageInsets:UIEdgeInsetsMake(10, 0, -10, 0)];  
32.           
33. //        [item setImageInsets:UIEdgeInsetsMake(0, -30, 0, 30)];  
34.           
35.  setImageInsets:UIEdgeInsetsMake(0, -30, 0, 30)];  
36.           
37.     }  
38.       
39. //    UITabBarButton;  
40. //    UIButton;  
41.       
42. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];  
43. .bounds = CGRectMake(0, 0, 30, 80);  
44. .backgroundColor = [UIColor redColor];  
45. .center = CGPointMake(self.tabBar.frame.size.width/2, self.tabBar.frame.size.height/2 - 20);  
46.       
47. //    [self.tabBar setShadowImage:IMG(@"transparent")];  
48.       
49. //    button.center = self.tabBar.center;  
50.       
51. self.tabBar addSubview:button];  
52.       
53. @"self tabBar is %@", self.tabBar.subviews);  
54.       
55. //    [self.tabBar.superview addSubview:button];  
56.       
57. //    [[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];  
58.       
59. //    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];  
60.       
61. self.tabBar.backgroundImage = [[self class] createImageWithColor:[UIColor cyanColor]];  
62. self.tabBar.shadowImage = [UIImage new];  
63.       
64. }  
65.   
66. /**
67.  * 将UIColor变换为UIImage
68.  *
69.  **/  
70. + (UIImage *)createImageWithColor:(UIColor *)color  
71. {  
72. 0.0f, 0.0f, 1.0f, 1.0f);  
73. .size);  
74.     CGContextRef context = UIGraphicsGetCurrentContext();  
75.  CGColor]);  
76.     CGContextFillRect(context, rect);  
77. UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();  
78.     UIGraphicsEndImageContext();  
79.       
80. return theImage;  
81. }  
82.   
83. - (void)didReceiveMemoryWarning {  
84. super didReceiveMemoryWarning];  
85. // Dispose of any resources that can be recreated.  
86. }  
87.   
88. /*
89. #pragma mark - Navigation
90. 
91. // In a storyboard-based application, you will often want to do a little preparation before navigation
92. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
93.     // Get the new view controller using [segue destinationViewController].
94.     // Pass the selected object to the new view controller.
95. }
96. */  
97.   
98. @end