本文介绍了PK在暗模式和亮模式下绘制不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在暗模式下使用 PKDrawing 时,由 imageFromRect:scale:返回白色的钢笔画.在灯光模式下,它使用黑色.背景通常是透明的.

When using PKDrawing in dark mode the image generated by imageFromRect:scale: returns pen drawings in white color. In light mode it uses black color. The background is usually transparent.

问题:如何强制PKDrawing始终表现得像灯光模式?

Question: How can PKDrawing be forced to always behave like in light mode?

推荐答案

您可以使用traitCollection.performAsCurrent:

You can do it like this, by using 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
}

这篇关于PK在暗模式和亮模式下绘制不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 23:45
查看更多