隱藏的最常見的操作埂软,置其為透明??
在TabBarVC里
- (void)viewDidLoad {
[super viewDidLoad];
YTTabBar *tabBar = [[YTTabBar alloc] init];
tabBar.tbDelagete = self;
[self setValue:tabBar forKeyPath:@"tabBar"];
UIImage *bgImg = [UIImage imageWithColor:[UIColor clearColor] size:CGSizeMake(SCREEN_Width, TabBarHeight)];
[self.tabBar setBackgroundImage:bgImg];
[self.tabBar setShadowImage:bgImg];
}
修改分割線顏色
點(diǎn)xcode的Debug View Hierarchy可以看到,tabBar上有一條細(xì)線瘟仿,其實(shí)就是一個(gè)超出父視圖0.5像素的UIImageView。
那么风响,我們就可以置空tabbar的背景圖和陰影镰禾,插入一個(gè)View,設(shè)成自己需要的顏色顾腊。
[self.tabBar setBackgroundImage:[UIImage new]];
[self.tabBar setShadowImage:[UIImage new]];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -0.5, SCREEN_Width, 0.5)];
view.backgroundColor = HEXCOLOR(0xf5f5f5);
[[UITabBar appearance] insertSubview:view atIndex:0];
達(dá)成目標(biāo)??粤铭。
給UIImage加的Category里
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size{
if (size.width == 0 || size.height == 0) {
size = CGSizeMake(1, 1);
}
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context,color.CGColor);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}