Tencent / QMUI_iOS

QMUI iOS——致力于提高项目 UI 开发效率的解决方案
http://qmuiteam.com/ios
Other
7.05k stars 1.37k forks source link

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

Closed jiasongs closed 1 year ago

jiasongs commented 2 years ago

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

截图

图片

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

Demo: QMUIDemo_iOS.zip

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

其他信息

MoLice commented 1 year ago

经测试,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 commented 1 year ago

已发布 4.5.0 修复该问题。