作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
类似于How to use dark mode in simulator iOS 13?和 How to enable Dark Mode on the Simulator? ,如何在 Xcode Swift Playground Live View 中启用深色模式?
最佳答案
您可以使用 overrideUserInterfaceStyle
在任何 View 中测试它
例如,您可以将这段代码粘贴到 playground 中进行检查(已在 Xcode 11.3.1 中测试):
import Foundation
import PlaygroundSupport
extension UIColor {
static var primary: UIColor {
UIColor { trait -> UIColor in
return trait.userInterfaceStyle == .light ? .black : .white
}
}
static var secondary: UIColor {
UIColor { trait -> UIColor in
return trait.userInterfaceStyle == .light ? .white : .black
}
}
}
class DarkModeTestView: UIView {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 375, height: 300))
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .secondary
label.text = "This text should be displayed in black for light mode and white for dark mode"
label.textColor = .primary
label.numberOfLines = 0
addSubview(label)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
let testView = DarkModeTestView(frame: CGRect(x: 0, y: 0, width: 375, height: 300))
testView.overrideUserInterfaceStyle = .dark // Change here .light or .dark
PlaygroundPage.current.liveView = testView
关于xcode - 如何在 iOS Xcode Swift Playground 上模拟黑暗模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60079597/
我正在.vimrc中用这些配置我的vim colorscheme。 "Color scheme syntax enable set background = dark colorsche
我是一名优秀的程序员,十分优秀!