UITabBarController的item间距能不能设置
UITabBarController的每个item不设title的话,那个title还是会占据着最下面那一行的位置,该怎么去隐藏它让那个位置空出来
可以换一种方案,调整UIBarItem的imageInsets使图片居中 (我假设你真正想要的是让图片居中显示)
[self.tabBarItem setImageInsets:UIEdgeInsetsMake(10, 0, -10, 0)];
很重要的一点,设置UIEdgeInsetsMake
的top
和bottom
属性为相反数,
否则会发生点击item后拖动,item会发生形变。
//
// RootViewController.m
// test_storyBoard_ipad
//
// Created by admin on 3/4/16.
// Copyright © 2016 jeffasd. All rights reserved.
//
#import "RootViewController.h" //父类 UITabbarController
@interface RootViewController ()
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// [self.tabBarItem setImageInsets:UIEdgeInsetsMake(10, 0, -10, 0)];
// [self.tabBarItem setImageInsets:UIEdgeInsetsMake(30, 0, -30, 0)];
// self.tabBar.items
for (UITabBarItem *item in self.tabBar.items) {
// UIEdgeInsets insets = {top, left, bottom, right};
// [item setImageInsets:UIEdgeInsetsMake(10, 0, -10, 0)];
// [item setImageInsets:UIEdgeInsetsMake(0, -30, 0, 30)];
[item setImageInsets:UIEdgeInsetsMake(0, -30, 0, 30)];
}
// UITabBarButton;
// UIButton;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.bounds = CGRectMake(0, 0, 30, 80);
button.backgroundColor = [UIColor redColor];
button.center = CGPointMake(self.tabBar.frame.size.width/2, self.tabBar.frame.size.height/2 - 20);
// [self.tabBar setShadowImage:IMG(@"transparent")];
// button.center = self.tabBar.center;
[self.tabBar addSubview:button];
NSLog(@"self tabBar is %@", self.tabBar.subviews);
// [self.tabBar.superview addSubview:button];
// [[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];
// [[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];
self.tabBar.backgroundImage = [[self class] createImageWithColor:[UIColor cyanColor]];
self.tabBar.shadowImage = [UIImage new];
}
/**
* 将UIColor变换为UIImage
*
**/
+ (UIImage *)createImageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
https://segmentfault.com/q/1010000000362020