Sorry for posting again but I can’t work out this problem.
I’m trying to make my ScrollView the same width as my List.
Previously I did manage to get these things the same width, but then my ScrollView didn’t have a scrollbar. So I started all over again and, while I got the scrollbar to be visible, I now can’t work out how to get these widths the same size.
In the code below, I can adjust the List’s width but I can’t for the Scrollview. And that’s weird. So I must be doing it wrong. Anyway I’ve tried various things but if someone could help me out with this that would be good.
Thanks!
I’m trying to make my ScrollView the same width as my List.
Previously I did manage to get these things the same width, but then my ScrollView didn’t have a scrollbar. So I started all over again and, while I got the scrollbar to be visible, I now can’t work out how to get these widths the same size.
In the code below, I can adjust the List’s width but I can’t for the Scrollview. And that’s weird. So I must be doing it wrong. Anyway I’ve tried various things but if someone could help me out with this that would be good.
Thanks!
Swift:
import SwiftUI
struct ContentView: View
{
@State var selection: String?
let names = ["First", "Second", "Third"]
var body: some View
{
TabView
{
VStack
{
List(selection: $selection)
{
ForEach(names, id: \.self)
{
item in Text(item)
}
}
.border(Color.black, width: 1)
.frame(width: 100, height: 100)
ScrollView
{
ForEach(1..<100)
{ index in
Text("\(index)")
}
}
.border(Color.black, width: 1)
.frame(width: 100, height: 100)
}
.tabItem
{
Text("Tab 1")
}
}}}