tabBar 选中默认蓝色 ,取消选中(自定义)

- (void)viewDidLoad {

    [super viewDidLoad];

 

//    [self _initSubViewControllers];

//    [self _customTabBar];

    

//    [self.navigationItem setRightBarButtonItem:UIBarStyleDefault];

//    self.SerBar=[[UISearchBar alloc]initWithFrame:CGRectMake(self.view.frame.size.width-150, 20, 120, 40)];

    

    //    [self.SerBar setPlaceholder:@"search"];

//    [self.SerBar setPrompt:@"搜索"];//顶部提示文本,title

//    [self.SerBar setBarStyle:UIBarStyleBlackTranslucent];//搜索框样式

//    [self.SerBar setTintColor:[UIColor whiteColor]];

    

//    [self.SerBar setShowsBookmarkButton:NO];

    

//    [self.SerBar setTranslucent:YES];//透明

//    [self.view addSubview:self.SerBar];

    方法二

    NSMutableDictionary *attrs=[NSMutableDictionary dictionary];

    //设置字体大小

    attrs[NSFontAttributeName]=[UIFont systemFontOfSize:13];

    

    //设置字体颜色

    attrs[NSForegroundColorAttributeName]=[UIColor colorWithRed:0.4 green:0.4 blue:0.6 alpha:1];

    

    //初始化一个字典

    NSMutableDictionary *Selectedattrs=[NSMutableDictionary dictionary];

    //设置字体大小

    Selectedattrs[NSFontAttributeName]=attrs[NSFontAttributeName];

    //设置字体颜色

    Selectedattrs[NSForegroundColorAttributeName]=[UIColor colorWithRed:0.3 green:0.5 blue:0.6 alpha:1];

    UITabBarItem *item=  [UITabBarItem appearance];

    

    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];

    [item setTitleTextAttributes:Selectedattrs forState:UIControlStateSelected];

    //添加子控制器

    

    [self setupchidVc:[HomeViewController new] title:@"主页" image:@"-1.png" selectedimage:@"T1"];

    

    [self setupchidVc:[DSDieQuoteViewController new] title:@"模报" image:@"-2.png" selectedimage:@"T2"];

    

    [self setupchidVc:[WXViewController new]  title:@"校谈" image:@"-3.png" selectedimage:@"T3"];

    

    

}

//-(void)_customTabBar{

//    

//    for (UIView *subView in self.tabBar.subviews) {

//        //        移除

//        [subView removeFromSuperview];

//    }

 

//    底部图片

//    [self.tabBar setBackgroundImage:[UIImage imageNamed:@"1.111png"]];

//    //    创建背景选中的图片

//    _selectV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 42, 42)];

    按钮图片

//    _selectV.image = [UIImage imageNamed:@"selectTabbar_bg_all.png"];

//    

//    [self.tabBar addSubview:_selectV];

    // 创建标签栏按钮

    //    获取所有按钮的图片

//    NSArray *imageNames = @[@"-1.png",@"-2.png",@"-3.png"];

//    NSArray *titles = @[@"主页",@"模报",@"校谈"];

    // 创建按钮

//    float button_width = self.view.frame.size.width / imageNames.count;

//    for (int i = 0; i < imageNames.count; i++) {

//        // 创建按钮

//        DSTabBarItem *item = [[DSTabBarItem alloc] initWithFrame:CGRectMake(i * button_width, 0, button_width, 49)];

//        // 设置tag

//        item.tag = i;

//        // 设置标题

//        item.titleName = titles[i];

//        // 设置图片

//        item.imageName = imageNames[i];

//        // 添加事件

//        [item addTarget:self action:@selector(itemAction:) forControlEvents:UIControlEventTouchUpInside];

//        

//        [self.tabBar addSubview:item];

        // 如果当前创建的是第一个按钮

//        if (i == 0) {

//            _selectV.center = item.center;

//        }

    

        

//    }

//}

-(void)setupchidVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image  selectedimage:(NSString *)selectedimage

{

    vc.tabBarItem.title=title;

    vc.tabBarItem.image=[UIImage imageNamed:image];

    vc.tabBarItem.selectedImage=[UIImage imageNamed:selectedimage];

    [self addChildViewController:vc];

    

    //取消选中时的背景色

    vc.tabBarItem.selectedImage = [vc.tabBarItem.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

}

 

转载于:https://www.cnblogs.com/wujie123/p/5511132.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值