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

UIImageView、UIButton 配合 template image 使用时无法通过 tintColor 来修改图片的颜色 #1418

Closed
CloudlessMoon opened this issue Jul 6, 2022 · 2 comments
Labels

Comments

@CloudlessMoon
Copy link

CloudlessMoon commented Jul 6, 2022

Bug 表现
UIButton.tintColor、UIImageView.tintColor为QMUIThemeColor,Image为UIImageRenderingModeAlwaysTemplate,「手动」切换主题后不生效,但是系统的主题切换是生效的

截图
图片

如何重现
1.图片
2.在QDThemeViewController.m中点击按钮切换主题

Demo:
QMUIDemo_iOS.zip

预期的表现
UIButton.tintColor、UIImageView.tintColor为QMUIThemeColor也可以正常生效

其他信息

  • 设备: iPhone
  • iOS 版本: iOS 15.x
  • Xcode 版本: Xcode 13.4
  • QMUI 版本: 4.4.3
@CloudlessMoon CloudlessMoon changed the title UIButton.tintColor对QMUIThemeColor不起作用 UIButton.tintColor、UIImageView.tintColor对QMUIThemeColor不起作用 Jul 8, 2022
@MoLice MoLice changed the title UIButton.tintColor、UIImageView.tintColor对QMUIThemeColor不起作用 UIImageView、UIButton 配合 template image 使用时无法通过 tintColor 来修改图片的颜色 Jul 20, 2022
@MoLice
Copy link
Collaborator

MoLice commented Jul 20, 2022

经测试,iOS 13-15 都有这个问题,iOS 12 及以下没问题是因为我们在 QMUIThemePrivate 里对 iOS 12 及以下的版本 hook 了 -[UIView setTintColor:],主动对 QMUIThemeColor 做一次 copy 从而触发系统的自动刷新。iOS 13 及以上没做这个处理,在手动切换 theme 时就出问题了。

UIImageView 系统没重写 setTintColor:。UIButton 重写了但有调用 super,所以统一在 -[UIView setTintColor:] 内处理即可。

新版本会修复该问题,在此之前可本地修改 QMUIThemePrivate.m 里的 UIView (QMUIThemeCompatibility),把 hook -[UIView setTintColor:] 外面判断 iOS 版本的 if 去除即可。

@MoLice MoLice added the bug label Jul 21, 2022
@MoLice
Copy link
Collaborator

MoLice commented Aug 10, 2022

已发布 4.5.0 修复该问题。

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