简体   繁体   English

Swift 将文本颜色更改为深色/浅色模式

[英]Swift change text color to dark/lightmode

I am trying to change the text color in a UITextView from light grey to white/black.我正在尝试将 UITextView 中的文本颜色从浅灰色更改为白色/黑色。

So the new text color should be white when the dark mode is on and the text color should be black when the light mode is on.因此,当打开深色模式时,新的文本颜色应该是白色,而当打开浅色模式时,文本颜色应该是黑色。

You can set the UIColor to.label您可以将 UIColor 设置为 .label

textView.textColor = .label

This should use the system label colour which is back against a white background and vice versa这应该使用系统 label 颜色,它背对着白色背景,反之亦然

You can also create your own dark/light colours in the assets file.您还可以在资产文件中创建自己的深色/浅色。 在此处输入图像描述

And then use them in code or the interface builder.然后在代码或界面生成器中使用它们。

textView.textColor = UIColor.init(named: "myBlueColor")

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

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