🚫view.foreground()
此文作廢 ❗️
定義
swift⟩ custom ⟩ extension ⟩ View ⟩ .foreground()
此文作廢。請用: view.foregroundStyle()❗️
.foregroundColor() 只能讓我們設定「前景色」,如果要套用諸如漸層這些比較花俏的東西時,就不行。因此,下面我們自己開發可以套用「任何 View」到前景的 extension。

import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
Text("SwiftUI is awesome!")
.font(.largeTitle)
.foreground(Gradient.horizontal(.red, .orange))
}
}
PlaygroundPage.current.setLiveView(ContentView())
參考資料
Last updated
Was this helpful?