gpt4 book ai didi

swiftui - 仅在符号外的 Swift UI 着色

转载 作者:行者123 更新时间:2023-12-05 02:40:11 25 4
gpt4 key购买 nike

这里有两个 SF 符号,其中一个带有一些阴影。

enter image description here

如您所见,不仅第二个符号的外部有阴影,内部也有阴影。我将如何只遮蔽外部,使内部空白留白而不是遮蔽?理想情况下,解决方案适用于其他 SF 符号,因为我计划对不仅仅是这个符号进行着色。

代码:

struct exampleSymbol: View {
var body: some View {
Image(systemName: "text.bubble.fill")
.foregroundColor(.blue)
.font(.system(size: 100))
}
}

struct stack: View {
var body: some View {
VStack {
exampleSymbol()
exampleSymbol()
.shadow(color: .gray, radius: 2, x: 3, y: 3)
}
}
}

最佳答案

这在 iOS 15 中是可能的,使用 symbolRenderingMode(_:).palette .

       /// Note: This should be capitalized
struct ExampleSymbol: View {
var body: some View {
Image(systemName: "text.bubble.fill")
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .blue)
.font(.system(size: 100))
}
}

struct ContentView: View {
var body: some View {
ExampleSymbol()
.shadow(color: .gray, radius: 2, x: 3, y: 3)
}
}

结果:

3 lines inside bubble icon are white

对于 iOS 15,您需要制作自己的自定义图标。

关于swiftui - 仅在符号外的 Swift UI 着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68697042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com