skip to Main Content

I have a List with Sections :

    List {
        ForEach((1...3), id: .self) { _ in
            Section(
                header: Text("My Section")
                            .font(.system(.title3))
                            .fontWeight(.bold)
                            .foregroundColor(.primary),
                content: {
                    ForEach((1...5), id: .self) { _ in
                        Text("My Row")
                    }
                }
            )
        }
    }

Here is the result on an iPhone 8 simulator with iOS 14.5:

iPhone8_iOS14.5

And here the result on an iPhone 8 simulator with iOS 15:

iPhone8_iOS15

I want iOS15 list to be equal to iOS14.5 one. I can remove horizontal padding by adding .listStyle(PlainListStyle()) to the List but the header of the section still have different vertical padding.

iPhone8_iOS15_PlainList

Is there a way to have the same vertical header padding as iOS14.5 ?

Environment:

  • iOS 15 RC
  • XCode 13 RC

3

Answers


  1. Chosen as BEST ANSWER

    Finally, what suited me the most was to add

    if #available(iOS 15.0, *) {
        UITableView.appearance().sectionHeaderTopPadding = 0
    }
    

    In AppDelegate didFinishLaunchingWithOptions function


  2. Change list’s style to GroupedListStyle using the .listStyle() modifier.

    .listStyle(GroupedListStyle())
    
    

    Header without gray backgrounnd

    .listStyle(PlainListStyle())
    
    

    More info

    https://developer.apple.com/documentation/swiftui/liststyle

    Login or Signup to reply.
  3. You can try setting the defaultMinListHeaderHeight in the environment:

    List {
    ...
    }
    .environment(.defaultMinListHeaderHeight, 16)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search