Skip to content

Trying to add overlay in SwiftUI #302

@dosht

Description

@dosht

I'm trying to add something like CurrentLineView to display other information like Sunrise and Sunset, but I can't access the scroll position or something similar to calculate its position. Do you have an idea how I can do this?
Here is my code to explain what I'm trying to do:

struct CalendarContentView: View {
    @ObservedObject var viewModel: CalendarViewModel = CalendarViewModel()
    @State var test: String = "test"
    
    var body: some View {
        GeometryReader { geo in
            CalendarDisplayView(events: $viewModel.events, geo: geo, test: $test)
                .overlay {
                    ZStack {
                        Text("Sunrise 6:35 AM")
                            .position(x: 110, y: geo.size.height / 2 - 12)
                            .foregroundColor(Color.blue)
                        Path() { path in
                            path.move(to: CGPoint(x: 44, y:  geo.size.height / 2 - 1))
                            path.addLine(to: CGPoint(x: 44, y:  geo.size.height / 2))
                            path.addLine(to: CGPoint(x: geo.size.width, y:  geo.size.height / 2))
                            path.addLine(to: CGPoint(x: geo.size.width, y:  geo.size.height / 2 - 1))
                        }.fill(Color.blue)
                    }
                }
        }
    }
}

simulator

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions