「SwiftUI」background関数でアイコンの背景色を変えるサンプル

2022年3月28日

書式
.background(Color.カラー名)
background関数を利用して背景色を変えます。

使用例

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")
.background(Color.red)
}
}
struct ContentView: View { var body: some View { Image(systemName: "logo.circle") .background(Color.red) } }
struct ContentView: View {
    var body: some View {
        Image(systemName: "logo.circle")
            .background(Color.red)
    }
}

結果
アイコンの背景色は赤を変えます。

Swift

Posted by arkgame