1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SwiftUI-Listの背景色の変更(iOS16~)

Posted at

はじめに

SwiftUIのList,
とても便利で、皆さんよく使用されると思いますが、Listの背景色を変えるのが、ひと手間かかっていました。
(UITableView.appearance()で色を変更していた)

今回、iOS16からの対応で、scrollContentBackground(_:)を使用する事で、簡単に設定できるようになりましたので、紹介したいと思います😀

サンプルAPP

import SwiftUI

struct ContentView: View {

    var body: some View {
        List{
            Section("sample"){
                Text("A")
                Text("B")
            }
        }
        // Listの背景色を無効化
        .scrollContentBackground(.hidden)
        // 色の指定
        .background(Color.red)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

スクリーンショット 2022-10-15 7.53.52.png

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?