Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS Xcode Swift游乐场上模拟暗模式_Xcode_Swift Playground_Xcode11_Ios Darkmode - Fatal编程技术网

如何在iOS Xcode Swift游乐场上模拟暗模式

如何在iOS Xcode Swift游乐场上模拟暗模式,xcode,swift-playground,xcode11,ios-darkmode,Xcode,Swift Playground,Xcode11,Ios Darkmode,与和类似,如何在Xcode Swift Playerd Live View中启用暗模式?模拟器很可能是实际设备。对于此解决方案,请在Xcode中运行模拟器。模拟器主屏幕显示后,转到模拟器上的设置菜单,在设置菜单上有开发人员菜单。单击developer菜单,您将看到深色外观开关。如果您切换该条,则所有应用程序都将在黑暗模式下运行。(如果您的应用程序具有暗模式版本) 您可以在任何视图中使用overrideUserInterfaceStyle 例如,您可以将此代码粘贴到游乐场中进行检查(在Xcode

与和类似,如何在Xcode Swift Playerd Live View中启用暗模式?

模拟器很可能是实际设备。对于此解决方案,请在Xcode中运行模拟器。模拟器主屏幕显示后,转到模拟器上的设置菜单,在设置菜单上有开发人员菜单。单击developer菜单,您将看到深色外观开关。如果您切换该条,则所有应用程序都将在黑暗模式下运行。(如果您的应用程序具有暗模式版本)


您可以在任何视图中使用
overrideUserInterfaceStyle

例如,您可以将此代码粘贴到游乐场中进行检查(在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