美文网首页
iOStabbar 添加自定义颜色的图片

iOStabbar 添加自定义颜色的图片

作者: 梁苏珍 | 来源:发表于2017-07-07 13:37 被阅读0次

    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;

    }

    相关文章

      网友评论

          本文标题:iOStabbar 添加自定义颜色的图片

          本文链接:https://www.haomeiwen.com/subject/leilhxtx.html