UITabBarController * tabBarCT = [[UITabBarController alloc]init];
tabBarCT.viewControllers = array;
UIApplication *application = [UIApplication sharedApplication];
UIWindow *window = [application.windows objectAtIndex:0];
window.rootViewController = tabBarCT;
tabBarCT.selectedIndex = 0;
//设置为半透明 yes 这个是系统的设置的
tabBarCT.tabBar.translucent = YES;
tabBarCT.tabBar.backgroundImage = [self createImageWithColor:[UIColor yellowColor]];
// // 点击时图片变成红色
// tabBarCT.tabBar.tintColor = [UIColor yellowColor];
tabBarCT.tabBar.tintColor = [UIColor blackColor];
- (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 *myImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return myImage;
}
iOS用颜色值创建图片
- (UIImage *) createImageWithColor: (UIColor *) color
{
CGRect rect = CGRectMake(0.0f,0.0f,1.0f,1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [colorCGColor]);
CGContextFillRect(context, rect);
UIImage *myImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return myImage;
}
网友评论