Swift 在SwitUI中显示UIImage为深色-Apple Watch

Swift 在SwitUI中显示UIImage为深色-Apple Watch,swift,swiftui,watchkit,apple-watch,watchos,Swift,Swiftui,Watchkit,Apple Watch,Watchos,我不明白为什么汽车systemName图像没有出现在Apple Watch模拟器上。(它是黑色的) (屏幕完全是黑色的,就像没有向视图添加任何内容一样)我想应该是这样的 struct ContentView: View { var body: some View { Image(systemName: "car") // < Native SwiftUI } } 一个解决方案是将UIImage颜色设置为白色,这样它将是可见的 Image(uiImage:

我不明白为什么汽车systemName图像没有出现在Apple Watch模拟器上。(它是黑色的)


(屏幕完全是黑色的,就像没有向视图添加任何内容一样)

我想应该是这样的

struct ContentView: View {
    var body: some View {
        Image(systemName: "car") // < Native SwiftUI
    }
}


一个解决方案是将UIImage颜色设置为白色,这样它将是可见的

Image(uiImage: UIImage(systemName: "car")!.maskWithColor(color: .white)!)
maskWithColor来自哪里


@FirsfNameLastname出于好奇,为什么是UIImage?要在UIKit目标上共享?
Image(uiImage: UIImage(systemName: "car")!).colorInvert()
Image(uiImage: UIImage(systemName: "car")!.maskWithColor(color: .white)!)
extension UIImage {

    func maskWithColor(color: UIColor) -> UIImage? {
        let maskImage = cgImage!

        let width = size.width
        let height = size.height
        let bounds = CGRect(x: 0, y: 0, width: width, height: height)

        let colorSpace = CGColorSpaceCreateDeviceRGB()
        let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
        let context = CGContext(data: nil, width: Int(width), height: Int(height), bitsPerComponent: 8, bytesPerRow: 0, space: colorSpace, bitmapInfo: bitmapInfo.rawValue)!

        context.clip(to: bounds, mask: maskImage)
        context.setFillColor(color.cgColor)
        context.fill(bounds)

        if let cgImage = context.makeImage() {
            let coloredImage = UIImage(cgImage: cgImage)
            return coloredImage
        } else {
            return nil
        }
    }

}