Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here's an example of a horizontal calendar layout using SwiftUI:

struct CalendarView: View {

    private let weekDays = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
    private let dates = (1..<32).map { $0 }

    var body: some View {
        VStack {
            HStack {
                ForEach(weekDays, id: \.self) { day in
                    Text(day)
                        .font(.headline)
                        .padding(.horizontal, 4)
                        .frame(width: UIScreen.main.bounds.width / 7)
                }
            }
            Divider()
            VStack {
                ForEach(dates, id: \.self) { date in
                    Text(String(date))
                        .padding(.horizontal, 4)
                        .frame(width: UIScreen.main.bounds.width / 7)
                }
            }
        }
    }
}

In this example, we have an array of week days and an array of dates. We use two ForEach loops to display them as a calendar, with the week days displayed horizontally and the dates displayed vertically. We use UIScreen.main.bounds.width to dynamically calculate the width of each cell based on the screen size.

Note that this is just a simple example and you may want to customize the layout and styling to better fit your needs.