ios ~ UITabBarController tabBar配景致

开发者 2024-9-26 16:19:01 49 0 来自 中国
tabbar 做个条记。


  • 改变tabbar的选中的item的字体颜色
    self.tabbar.tintColor = [UIColor redColor];
  • 改变tabbar未选中的item的字体颜色
    self.tabbar.unselectedItemTintColor = [UIColor yellowColor];
  • 改变tabbar的配景颜色

    • 方法1
    self.tabbar.barTintColor = [UIColor redColor];self.tabbar.translucent =  NO;

    • 方法2
    [[UITabBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor redColor]]];
  • self.tabbar.translucent = NO干了什么

    • 是YES的时间,tabbar的视图层级是
      UITabBar-->UIBarBackground-->UIVisualEffectView-->UIVisualEffectBackdropView-->UIVisualEffectSubview-->UIVisualEffectSubview (决定tabbar颜色的视图)
    • 是NO的时间,tabbar的视图层级是
      UITabBar-->UIBarBackground-->UIImageView (决定tabbar颜色的视图)
    • YES还是NO,从颜色效果上,我没看出区别
    • translucent = NO 对UICollectionView截屏的影响,具体见第十一条

  • 使用方法2的时间,视图层级和self.tabbar.translucent = NO一摸一样,都是3层
  • 改变tabbar的配景颜色,又看到下面这个方法
         UIView *color_view = [[UIView alloc]initWithFrame:self.tabBar.bounds];     color_view.backgroundColor = [UIColor redColor];     [self.tabBar insertSubview:color_view atIndex:0];这个方法只是改变tabbar部分的配景颜色,tabbar到底部的安全区safeArea有一条是改变不了的。好比使用上面的方法设置tabbar为redcolor,tabbar下面的安全区有一条留白。
// 这是当self.tabBar.translucent = YES时,tabBar的UIVisualEffectView配景致    if (@available (iOS 15.0, *)) {        // iOS 15.0 及以上        UITabBarAppearance *appearance = [[UITabBarAppearance alloc] init];        [appearance configureWithOpaqueBackground];        appearance.backgroundColor = RGBA(236, 231, 222, 1);                self.tabBar.standardAppearance = appearance;        self.tabBar.scrollEdgeAppearance = self.tabBar.standardAppearance;    } else {                self.tabBar.barTintColor = RGBA(236, 231, 222, 1);    }    /**         // 当tabBar.translucent = NO 时,可以直接设置 tabBar.backgroundColor:         self.tabBar.translucent = NO;    self.tabBar.barTintColor = RGBA(236, 231, 222, 1);    self.tabBar.backgroundColor = UIColor.redColor;     */    /**    // swift:        if #available(iOS 15.0, *) {       let appearance = UITabBarAppearance()       appearance.configureWithOpaqueBackground()       appearance.backgroundColor = customColor       self.tabController.tabBar.standardAppearance = appearance       self.tabController.tabBar.scrollEdgeAppearance = self.tabController.tabBar.standardAppearance    }     */
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-18 18:28, Processed in 0.173561 second(s), 32 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表