CYLTabBarController icon indicating copy to clipboard operation
CYLTabBarController copied to clipboard

iOS 13, Tabbar顶部的黑线没法自定义。设置ShadowImage、Layer也不行

Open quietStefan opened this issue 5 years ago • 21 comments



Base Info for this issue

  1. Version:Latest Version as here (1.28.3)
  2. Language of App :Objective-C
  3. iOS System Version:iOS13
  4. Prototype(是否是真机):真机模拟器都一样
  5. Issue Type:Crash、Bug、Enhancement(希望能支持一个新需求)、Q-A

1. How to reproduce the problem.

2. Please help me in this way.

希望能修复iOS13系统下,tabbar顶部黑线问题,能实现自定义颜色,类似iOS12及以下的效果

3. Here is a Demo.

4. Here is my Debug log


quietStefan avatar Sep 12 '19 10:09 quietStefan

image

quietStefan avatar Sep 12 '19 10:09 quietStefan

@ChenYilong 麻烦楼主看下这问题

quietStefan avatar Sep 20 '19 08:09 quietStefan

控制器对象调用一下这个方法就行了 hideTabBarShadowImageView

lilinxuan avatar Sep 21 '19 06:09 lilinxuan

这样就完全去掉顶部的分割线了。 不是想要的效果呀

quietStefan avatar Sep 21 '19 06:09 quietStefan

那还不简单啊,先完全去掉,想要什么样的线自己写个view不就行了。😀

lilinxuan avatar Sep 21 '19 08:09 lilinxuan

先去掉,然后自己写一个线添加上去。

lilinxuan avatar Sep 21 '19 08:09 lilinxuan

这。。。不太合适吧。 那还不如直接把tabbar都用view自定义了。 貌似iOS13之后就没法遍历tabbar的shadowiamge了

quietStefan avatar Sep 21 '19 08:09 quietStefan

达到最终要的效果并且不影响任何其他。难道还不行?

lilinxuan avatar Sep 21 '19 08:09 lilinxuan

不太规范。,,

quietStefan avatar Sep 21 '19 08:09 quietStefan

现在的程序员基本都是搬砖。为了实现效果都在留坑。完成任务才是首位。这就是现实。

lilinxuan avatar Sep 21 '19 08:09 lilinxuan

iOS 13 tabbar添加了一个新属性 UITabBarAppearance 可以在这里设置

zhuzhiwen0527 avatar Sep 23 '19 10:09 zhuzhiwen0527

这个不行吧,我看了这个都是tabbar item的属性,还是不能像以前一样修改顶部线条颜色问题

quietStefan avatar Sep 23 '19 10:09 quietStefan

if (@available(iOS 13.0, *)) {
    UITabBarAppearance *standardAppearance = [[UITabBarAppearance alloc] init];
    UITabBarItemAppearance *inlineLayoutAppearance = [[UITabBarItemAppearance  alloc] init];
    [ inlineLayoutAppearance.normal setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:RGB(169, 181, 208)}];
    [ inlineLayoutAppearance.selected setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:CclearBlue(1)}];
    standardAppearance.stackedLayoutAppearance = inlineLayoutAppearance;
    standardAppearance.backgroundColor = [UIColor whiteColor];
    standardAppearance.shadowImage = [UIImage imageWithColor:CpaleGrey(1)];
    self.tabBar.standardAppearance = standardAppearance;
} else {
    // Override point for customization after application launch.
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:RGB(169, 181, 208)} forState:UIControlStateNormal];
       // 选中状态的标题颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:CclearBlue(1)} forState:UIControlStateSelected];
    [[UITabBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]]];
    [[UITabBar appearance] setShadowImage:[UIImage imageWithColor:CpaleGrey(1)]];
}

zhuzhiwen0527 avatar Sep 23 '19 10:09 zhuzhiwen0527

试下了,可以了。 谢谢大佬

quietStefan avatar Sep 23 '19 11:09 quietStefan

image

image

luoshihui avatar Sep 23 '19 12:09 luoshihui

上述方法修改后确实有效,但是修改后普通的tabbar 会比之前位置偏下了,请问下什么情况 @ChenYilong

Lee0820 avatar Sep 26 '19 03:09 Lee0820

if (@available(iOS 13.0, *)) {
    UITabBarAppearance *standardAppearance = [[UITabBarAppearance alloc] init];
    UITabBarItemAppearance *inlineLayoutAppearance = [[UITabBarItemAppearance  alloc] init];
    [ inlineLayoutAppearance.normal setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:RGB(169, 181, 208)}];
    [ inlineLayoutAppearance.selected setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:CclearBlue(1)}];
    standardAppearance.stackedLayoutAppearance = inlineLayoutAppearance;
    standardAppearance.backgroundColor = [UIColor whiteColor];
    standardAppearance.shadowImage = [UIImage imageWithColor:CpaleGrey(1)];
    self.tabBar.standardAppearance = standardAppearance;
} else {
    // Override point for customization after application launch.
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:RGB(169, 181, 208)} forState:UIControlStateNormal];
       // 选中状态的标题颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName:CclearBlue(1)} forState:UIControlStateSelected];
    [[UITabBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]]];
    [[UITabBar appearance] setShadowImage:[UIImage imageWithColor:CpaleGrey(1)]];
}

怎么swift 转化不过来

Xue765 avatar Nov 20 '19 07:11 Xue765

let inlineLayoutAppearance = UITabBarItemAppearance() inlineLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor : APP_TEXT_GRAY_COLOR,NSAttributedString.Key.font : UIFont.init(name: FONTNAME_REGULAR, size: 10*WPERCENT) as Any] appearance.stackedLayoutAppearance = inlineLayoutAppearance

Swift版本 ⏫

ZJF-Coder avatar Mar 24 '20 07:03 ZJF-Coder

@ZJF-Coder @luoshihui @zhuzhiwen0527 ,我这么设置了确实达到了设置分割线的效果,但是 CYLTabBarItemTitlePositionAdjustment设置的偏移量就失效了,是时机问题不对吗?

Lee0820 avatar May 03 '20 16:05 Lee0820

我今天刚注意到 13.4.1的手机上用老api,也可以,分割线可以设置成功,13.3的还是有问题

Lee0820 avatar May 04 '20 09:05 Lee0820

上述方法修改后确实有效,但是修改后普通的tabbar 会比之前位置偏下了,请问下什么情况 @ChenYilong

 相同的问题 https://github.com/ChenYilong/CYLTabBarController/issues/437

ChenYilong avatar Aug 27 '21 04:08 ChenYilong