Reputation: 2639
I am trying to create a WidgetKit extension for one of my apps. I would like to have a top-aligned label and some dynamic content.
The problem is that all content is centred. I want the label to be at the top and the container should fill the rest of the space. Within that container are the items (also not centred, starting from the top).
This is my code:
struct WidgetView : View
{
var data: DataProvider.Entry
var body: some View
{
Text("Test")
.font(Font.system(size: 14.0, weight: .medium, design: .default))
.fontWeight(.semibold)
.background(Color.white)
.foregroundColor(Color.red)
.padding(.top, 8.0)
ForEach(0 ..< 2, id: \.self)
{
_ in
Text("This is just some text")
}
}
}
This will result in the following view:
I tried adding a ScrollView
and a LazyVStack
. Now it looks just like I want it to look, but there is a red circle (probably not allowed in WidgetKit
?):
Is this possible? This is my first contact with SwiftUI
.
Upvotes: 1
Views: 296
Reputation: 258117
Use VStack
with spacer at the bottom
VStack {
Text("Test")
.font(Font.system(size: 14.0, weight: .medium, design: .default))
.fontWeight(.semibold)
.background(Color.white)
.foregroundColor(Color.red)
.padding(.top, 8.0)
ForEach(0 ..< 2, id: \.self)
{
_ in
Text("This is just some text")
}
Spacer()
}
Upvotes: 2