隐藏导航堆栈中的列表分隔符/分隔线

huangapple go评论62阅读模式
英文:

Hide list separator/divider in NavigationStack

问题

I have a problem with the sticky header in my view, when I scroll up I don't want that separator line on the video to be.

Just want to remove this separator, all list modifiers are not working for me.

My View code:

import SwiftUI

struct CalendarView: View {
    
    let dayLetters = ["S", "M", "T", "W", "T", "F", "S"]
    
    var body: some View {
        NavigationStack {
            List {
                Section {
                    RootView()
                } header: {
                    HStack {
                        ForEach(0..<dayLetters.count, id: \.self) { index in
                            Text(dayLetters[index])
                                .frame(maxWidth: .infinity)
                                .foregroundColor(.white)
                        }
                    }
                }
                .listRowInsets(EdgeInsets())
                .listRowSeparator(.hidden)
            }
            .navigationTitle("Calendar")
            .listStyle(.plain)
            .toolbar {
                ToolbarItem(placement: .navigationBarLeading) {
                    Button("Today") {
                        
                    }
                }
                ToolbarItem(placement: .navigationBarTrailing) {
                    Label("Transform Calendar", systemImage: "ellipsis")
                        .foregroundColor(.accentColor)
                }
                ToolbarItem(placement: .navigationBarTrailing) {
                    Button {
                        
                    } label: {
                        Label("Add", systemImage: "plus")
                    }
                }
            }
        }
    }
}

Image links:
隐藏导航堆栈中的列表分隔符/分隔线
隐藏导航堆栈中的列表分隔符/分隔线

英文:

I have a problem with the sticky header in my view, when I scroll up I don't want that separator line on the video to be.

Just want to remove this separator, all list modifiers are not working for me.

隐藏导航堆栈中的列表分隔符/分隔线

My View code:

import SwiftUI

struct CalendarView: View {
    
    let dayLetters = [&quot;S&quot;, &quot;M&quot;, &quot;T&quot;, &quot;W&quot;, &quot;T&quot;, &quot;F&quot;, &quot;S&quot;]
    
    var body: some View {
        NavigationStack {
            List {
                Section {
                    RootView()
                } header: {
                    HStack {
                        ForEach(0..&lt;dayLetters.count, id: \.self) { index in
                            Text(dayLetters[index])
                                .frame(maxWidth: .infinity)
                                .foregroundColor(.white)
                        }
                    }
                }
                .listRowInsets(EdgeInsets())
                .listRowSeparator(.hidden)
            }
            .navigationTitle(&quot;Calendar&quot;)
            .listStyle(.plain)
            .toolbar {
                ToolbarItem(placement: .navigationBarLeading) {
                    Button(&quot;Today&quot;) {
                        
                    }
                }
                ToolbarItem(placement: .navigationBarTrailing) {
                    Label(&quot;Transform Calendar&quot;, systemImage: &quot;ellipsis&quot;)
                        .foregroundColor(.accentColor)
                }
                ToolbarItem(placement: .navigationBarTrailing) {
                    Button {
                        
                    } label: {
                        Label(&quot;Add&quot;, systemImage: &quot;plus&quot;)
                    }
                }
            }
        }
    }
}

隐藏导航堆栈中的列表分隔符/分隔线

答案1

得分: 1

尝试将List替换为VStack。如果需要滚动,请考虑在ScrollView内嵌套LazyVStack

英文:

Do you have to be using List here? Try replacing List with a VStack. If you need scrolling, consider using a LazyVStack nested within a ScrollView.

huangapple
  • 本文由 发表于 2023年6月8日 00:45:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76425486.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定