sindresorhus / Settings

⚙ Add a settings window to your macOS app in minutes
MIT License
1.45k stars 100 forks source link

How to top-align section title with content? #70

Closed francisfeng closed 3 years ago

francisfeng commented 3 years ago

I have a section containing only one SwiftUI List view. How can I top-align the section title with and the list?

Can I achieve this with current version of Preference?

If not, maybe offer a parameter to customize this? I think I can help with it becuase I really need this.

The code:

struct ColorThemePane: View {
  let colorThemeOptions = ColorTheme.allCases
  @State var selectKeeper: Set<ColorTheme> = [Defaults[.colorTheme]]

  var body: some View {
    Preferences.Container(contentWidth: Preferences.PaneWidth) {

      Preferences.Section(title: "Color Theme:", bottomDivider: true) {
        List(colorThemeOptions, id: \.self, selection: $selectKeeper){ name in
          Text(name.rawValue)
        }.listStyle(PlainListStyle())
        .frame(width: 290, height: 150)
        .cornerRadius(6)

      }

    }
  }
}

The result: image

Related: #56

sindresorhus commented 3 years ago

https://github.com/sindresorhus/Preferences/releases/tag/v2.4.0