简体   繁体   English

视图背后的魔法自动适应 ios13 暗模式?

[英]Magic behind views automatically adapting to ios13 dark mode?

I found it quite weird that for new projects created by xcode 11 beta, common views like UILabel , UIButton in a storyboard can automatically adapt themselves to system theme changes without any code.我发现很奇怪,对于 xcode 11 beta 创建的新项目,情节UIButton中的UILabelUIButton等常见视图可以自动适应系统主题更改而无需任何代码。 But for my old projects still using XIB, even though all colors are set to default, they dont change when system theme changed, i still have to manually override traitCollectionDidChange and assign them system default values in order to make them change!但是对于我仍然使用 XIB 的旧项目,即使所有颜色都设置为默认值,当系统主题更改时它们不会更改,我仍然必须手动覆盖traitCollectionDidChange并为其分配系统默认值以使它们更改! What am i doing wrong?我究竟做错了什么? thanks.谢谢。

I figured out.我想通了。 The magic is the newly added system colors to UIColor on ios 13, for example, UIColor.systemBackgroundColor , it will be white in light mode and black in dark mode, once you assign a system color to a property, it always updates itself based on system theme.神奇的是在 ios 13 上为UIColor添加了新的系统颜色,例如UIColor.systemBackgroundColor ,它在浅色模式下为白色,在深色模式下为黑色,一旦您为属性分配系统颜色,它总是根据系统主题。 So i guess UIViews created in xcode 11 beta storyboards automatically have system colors on.所以我猜在 xcode 11 beta 故事板中创建的 UIViews 会自动启用系统颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM