Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.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 PK为暗模式和亮模式绘制不同的结果_Ios_Ios13 - Fatal编程技术网

Ios PK为暗模式和亮模式绘制不同的结果

Ios PK为暗模式和亮模式绘制不同的结果,ios,ios13,Ios,Ios13,在暗模式下使用PKDrawing时,生成的图像将返回白色钢笔图形。在灯光模式下,它使用黑色。背景通常是透明的 问题:如何强制PKDrawing始终像在灯光模式下一样工作?您可以使用traitCollection.performAsCurrent这样做: let darkImage = thumbnail(drawing: drawing, thumbnailRect: frameForImage, traitCollection: UITraitCollection(userInterfaceS

在暗模式下使用PKDrawing时,生成的图像将返回白色钢笔图形。在灯光模式下,它使用黑色。背景通常是透明的


问题:如何强制PKDrawing始终像在灯光模式下一样工作?

您可以使用traitCollection.performAsCurrent这样做:

let darkImage = thumbnail(drawing: drawing, thumbnailRect: frameForImage, traitCollection: UITraitCollection(userInterfaceStyle: .dark))

func thumbnail(drawing: PKDrawing, thumbnailRect: CGRect, traitCollection: UITraitCollection) -> UIImage {

    var image = UIImage()
    traitCollection.performAsCurrent {
        image = drawing.image(from: thumbnailRect, scale: 2.0)
    }
    return image
}

您可以使用traitCollection.performAsCurrent这样做:

let darkImage = thumbnail(drawing: drawing, thumbnailRect: frameForImage, traitCollection: UITraitCollection(userInterfaceStyle: .dark))

func thumbnail(drawing: PKDrawing, thumbnailRect: CGRect, traitCollection: UITraitCollection) -> UIImage {

    var image = UIImage()
    traitCollection.performAsCurrent {
        image = drawing.image(from: thumbnailRect, scale: 2.0)
    }
    return image
}

看一个例子看一个例子这太棒了!它工作得很好。谢谢Stefan,拯救了我的一天。这对ios来说非常有效——但你知道如何在OSX上做到这一点吗?这太棒了!它工作得很好。谢谢Stefan,拯救了我的一天。这对ios来说非常有效——但你知道如何在OSX上做到这一点吗?