用系统的TabBar不让系统渲染图片设置文字背影颜色

来源:互联网 发布:个性淘宝客服昵称 编辑:程序博客网 时间:2024/05/17 02:37

AppDelegate

    self.window=[[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];

    self.window.backgroundColor=[UIColorwhiteColor];

    CustomTabBar * cus=[[CustomTabBaralloc]init];

  //  cus.tabBar.backgroundImage=[UIImage imageNamed:@"tabbar"];

    //设置tabbar文字背影色

    cus.tabBar.tintColor=[UIColorcolorWithRed:1.000green:0.399blue:0.028alpha:1.000];

    self.window.rootViewController=cus;

    [self.windowmakeKeyAndVisible];

    return YES;

自定义的tabBar类


#import "CustomTabBar.h"

#import "FirstViewController.h"

#import "SecondViewController.h"

#import "ThreeViewController.h"

#import "FourViewController.h"

@interface CustomTabBar ()

@end

@implementation CustomTabBar

- (void)viewDidLoad {

    [superviewDidLoad];

   

    FirstViewController * fvc=[[FirstViewControlleralloc]init];

    UINavigationController * nav1=[[UINavigationControlleralloc]initWithRootViewController:fvc];

    fvc.title=@"first";


//    UIImage * img1=[UIImage imageNamed:@"卖汤汤"];

//    UIImage * imgS1=[UIImage imageNamed:@"卖汤汤A"];

//    nav1.tabBarItem.selectedImage=[imgS1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

//    nav1.tabBarItem.image=[img1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    

    //或者用

    

    nav1.tabBarItem.image=[[UIImageimageNamed:@"卖汤汤"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    

    nav1.tabBarItem.selectedImage=[[UIImageimageNamed:@"卖汤汤A"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    SecondViewController * svc=[[SecondViewControlleralloc]init];

    UINavigationController * nav2=[[UINavigationControlleralloc]initWithRootViewController:svc];

    svc.title=@"second";

    UIImage * img2=[UIImageimageNamed:@"精品汇"];

    UIImage * imgS2=[UIImageimageNamed:@"精品汇A"];

    nav2.tabBarItem.image=[img2imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    nav2.tabBarItem.selectedImage=[imgS2imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    ThreeViewController * tvc=[[ThreeViewControlleralloc]init];

    UINavigationController * nav3=[[UINavigationControlleralloc]initWithRootViewController:tvc];

    tvc.title=@"three";

    nav3.tabBarItem=[[UITabBarItemalloc]initWithTitle:@"three"image:[UIImageimageNamed:@"菜谱"]selectedImage:[UIImageimageNamed:@"菜谱A"]];

    UIImage * img3=[UIImageimageNamed:@"菜谱"];

    UIImage * imgS3=[UIImageimageNamed:@"菜谱A"];

    nav3.tabBarItem.selectedImage=[imgS3imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    nav3.tabBarItem.image=[img3imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    FourViewController * fouvc=[[FourViewControlleralloc]init];

    UINavigationController * nav4=[[UINavigationControlleralloc]initWithRootViewController:fouvc];

    fouvc.title=@"four";

    //UIEdgeInsets insets=UIEdgeInsetsMake(10,10, 10, 10);

    UIImage * img4=[UIImageimageNamed:@"我的"];

    UIImage * imgS4=[UIImageimageNamed:@"我的A"];

    img4=[img4 resizableImageWithCapInsets:insetsresizingMode:UIImageResizingModeTile];

    nav4.tabBarItem.image=[img4imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    nav4.tabBarItem.selectedImage=[imgS4imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    self.viewControllers=@[nav1,nav2,nav3,nav4];

}

@end


0 0