0

How do I properly setup a ScrollView with SwiftUI in a Mac app? The example below clips the last item.

import SwiftUI

struct NameRow: View {

    var name: String

    var body: some View {
        VStack {
            Spacer()
            Text("\(name)")
            Spacer()
            Divider()
        }.frame(width: 100, height: 40)
    }
}

struct ContentView: View {

    let names = ["Homer", "Marge", "Lisa", "Bart", "Maggie", "Krusty", "Burns", "Nelson", "Otto"]

    var body: some View {
        VStack {
            ScrollView {
                ForEach(names, id: \.self) { name in
                    NameRow(name: name)
                }
            }
        }.frame(width: 100, height: 160)
    }
}

As shown in the image, the last item is clipped by the window. This view is scrolled to the bottom but the "Otto" item does not fully display.

enter image description here

1 Answer 1

0

If you remove the .fullSizeContentView from the window initialization in AppDelegate.swift so it looks like the following, then it will fully display the list.

window = NSWindow(
    contentRect: NSRect(x: 0, y: 0, width: 480, height: 300),
    styleMask: [.titled, .closable, .miniaturizable, .resizable],
    backing: .buffered, defer: false)

I don't know if this is a bug or by design.

Sign up to request clarification or add additional context in comments.

1 Comment

Removing . fullSizeContentView fixes the issue. Thanks for the suggestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.