0
1

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 .listStyle(PlainListStyle()) の1番上と下の線を消したい

Posted at

困ったこと

.swift
    let items = ["hoge", "higa", "piyo"]
    
    var body: some View {
        VStack () {
            List {
                ForEach(0 ..< items.count) { index in
                    Text(items[index])
                }
            }
            .listStyle(PlainListStyle())
        }
    }

このコードを表示すると、こんな風に表示される

スクリーンショット 2021-12-27 23.27.22.png

1番上と下のライン消したいんだがどうしたらいいのやら

対応方法

SectionでList内を囲って、 .listSectionSeparator(.hidden) を指定すればOK

.swift
    let items = ["hoge", "higa", "piyo"]
    
    var body: some View {
        VStack () {
            List {
                Section() {
                    ForEach(0 ..< items.count) { index in
                        Text(items[index])
                    }
                }.listSectionSeparator(.hidden)
            }
            .listStyle(PlainListStyle())
        }
    }

スクリーンショット 2021-12-27 23.35.18.png

無事消えました🙏

参考

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?