如何在 SwiftUI 中更改 pdf 图标的颜色

Vic*_*rov 3 swiftui

我将 SF 符号导出为 pdf 图标,并将默认白色更改为黑色。我想将黑色改回白色。我发现这样.colorInvert做可以,但是当我放入ImageButton时又变黑了。

import SwiftUI

#if os(macOS)
extension Image {
    static func sfSymbol(_ systemName: String) -> some View {
        Image(systemName)
        .resizable()
        .aspectRatio(contentMode: .fit)
        .colorInvert()
        .frame(height: 20)
    }
}

struct ImageView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            Image.sfSymbol("square.and.arrow.down.fill")
            Button(action: {}, label: { Image.sfSymbol("square.and.arrow.down.fill") })
        }
    }
}
#endif
Run Code Online (Sandbox Code Playgroud)

PDF 图标:square.and.arrow.down.fill.imageset

在此输入图像描述

小智 7

我实际上遇到了同样的问题,并发现您必须将图标属性检查器中的渲染模式更改为“模板图像”。