Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UIKit Bug] iOS 14 修改 UITabBarAppearance.inlineLayoutAppearance.normal.titleTextAttributes[NSForegroundColorAttributeName] 会导致 UITabBarItem 文字无法完整展示 #1110

Closed
MoLice opened this issue Sep 28, 2020 · 5 comments
Labels

Comments

@MoLice
Copy link
Collaborator

MoLice commented Sep 28, 2020

截图
修改颜色后文字展示不完整:

不修改颜色则没问题:

如何重现

UITabBarAppearance *appearance = tabBarController.tabBar.standardAppearance;
appearance.inlineLayoutAppearance.normal.titleTextAttributes = @{NSForegroundColorAttributeName: UIColor.redColor};
tabBarController.tabBar.standardAppearance = appearance;

测试 Demo
(内附修复代码,在 UITabBar+Test.m 内,默认注释了)
TestTabBarAppearance.zip

预期的表现
UITabBarItem 文字完整展示。

其他信息

  • 设备: iPad、iPhone 横屏,反正只要是 UITabBarItem 图片和文字水平布局就会
  • iOS 版本: [iOS 14.0]
  • Xcode 版本: [Xcode 12.0]
@MoLice MoLice added the bug label Sep 28, 2020
@MoLice
Copy link
Collaborator Author

MoLice commented Sep 28, 2020

直接原因是 iPad/iPhone 横屏下会使用 UITabBar.standardAppearance.inlineLayoutAppearance,此时默认的 title font 类型为“UICTFontTextStyleFootnote”,而 UITabBar.stackedLayoutAppearance 下是“.SFUI-Medium”。

UITabBarButtonLabel 使用这种 font 时,sizeThatFits: 会返回错误的值,如果换成 UILabel,或者换其他 font,则没这种问题。

所以业务也可以通过手动指定一个普通的 UIFont 来避免这种情况。

@MoLice MoLice changed the title [UIKit Bug] iOS 14 通过 UITabBarAppearance 修改 titleTextAttributes[NSForegroundColor] 会导致 UITabBarItem 文字无法完整展示 [UIKit Bug] iOS 14 修改 UITabBarAppearance.inlineLayoutAppearance.normal.titleTextAttributes[NSForegroundColor] 会导致 UITabBarItem 文字无法完整展示 Sep 28, 2020
@MoLice MoLice changed the title [UIKit Bug] iOS 14 修改 UITabBarAppearance.inlineLayoutAppearance.normal.titleTextAttributes[NSForegroundColor] 会导致 UITabBarItem 文字无法完整展示 [UIKit Bug] iOS 14 修改 UITabBarAppearance.inlineLayoutAppearance.normal.titleTextAttributes[NSForegroundColorAttributeName] 会导致 UITabBarItem 文字无法完整展示 Sep 29, 2020
@MoLice
Copy link
Collaborator Author

MoLice commented Sep 29, 2020

已发布 4.2.1 修复该问题。

@horsley
Copy link

horsley commented May 24, 2021

image

设备型号 iPad Pro 12.9 第二代 (MQDD2ZP/A) iOS 14.0.1 依然出现这个问题,这里fontFamily 是system-ui所以没有应用到这个fix,需要一个pr么? @MoLice mo

@MoLice
Copy link
Collaborator Author

MoLice commented May 24, 2021

@horsley 可以

@MoLice
Copy link
Collaborator Author

MoLice commented Aug 22, 2021

image

设备型号 iPad Pro 12.9 第二代 (MQDD2ZP/A) iOS 14.0.1 依然出现这个问题,这里fontFamily 是system-ui所以没有应用到这个fix,需要一个pr么? @MoLice mo

@horsley 不再采用判断 fontFamily 的方式,具体请查看 #1285

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants