「SwiftUI」foregroundColorでアイコンの色を変える

2022年3月28日

書式
.foregroundColor(Color.カラー名)
foregroundColor関数を利用してアイコンの色を変えます。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
struct ContentView: View {
var body: some View {
Image(systemName: "logo.circle")
.foregroundColor(Color.red)
}
}
struct ContentView: View { var body: some View { Image(systemName: "logo.circle") .foregroundColor(Color.red) } }
struct ContentView: View {
    var body: some View {
        Image(systemName: "logo.circle")
            .foregroundColor(Color.red)
    }
}

結果
アイコンの色を赤に変えます。

Swift

Posted by arkgame