Joh*_*sen 3 shading swiftui sf-symbols
这里有两个 SF 符号,其中一个带有一些阴影。
正如您所看到的,不仅第二个符号的外部有阴影,内部也有阴影。我如何仅对外部进行着色,而使内部空白保持白色而不是阴影?理想情况下,解决方案适用于其他 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)
}
}
}
Run Code Online (Sandbox Code Playgroud)
这在 iOS 15 中是可能的,使用symbolRenderingMode(_:)of .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)
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
对于 iOS 15 以下版本,您需要制作自己的自定义图标。
| 归档时间: |
|
| 查看次数: |
683 次 |
| 最近记录: |