1

From what I understand there is no dedicated table view class for use in SwiftUI. What is the best way to create such a table yourself?

In fact, I am looking for something a bit different for a weekly schedule view. I am trying to build a view such that an Item can be between two rows, for example if a meeting is between 9:00 and 10:30 the representation of the meeting will overflow the 10:00 row to a middle imaginary line between 10:00 and 11:00.

I started building something like that using ScrollView and just basic HStacks and VStacks and postioning of Text controls but I figured there must be a much better, reliable and easier way..

Example of a code to create a row and coulmn will be helpful.

RT.
  • 423
  • 3
  • 12
  • a `List` or the new `LazyHGrid`? You will need to handle the various possibilities in the "cell" views - One where the event continues out of the bottom, which would be followed by one where the event continues in from the top and so on. – Paulw11 Jul 02 '20 at 01:01

1 Answers1

1

I guess you are looking for a List here. List is the alternative to UITableView in Swift. You could divide the entire time into segments of 1 hr each and present a row in the List for each segment.

For adding the representation of a meeting overflow, you can set the height of a subview of a row to the time overflow. For example, if the meeting is between 10 and 11:30, the 10-11 row will be full height. For the next row, i.e. 11-12,

heightFactor = timeElapsed/60 row height = heightFactor * maxRowHeight.

(Here, it would be 30/60 * maxRowHeight = 0.5 * maxRowHeight).

The height can be adjusted in the code using GeometryReader

GeometryReader { geometry in
            VStack(spacing: 0) {
                Text("")
                    .frame(width: geometry.size.width, height: heightFactor * geometry.size.height)//rowHeight is as calculated above
                    .background(Color.yellow)
                Spacer()
            }
        }
Subha_26
  • 440
  • 4
  • 14
  • My intention is to create a weekly view and not a daily list, so there is a problem with the width depending on geometry since there might not be any cell in the next day at the same hour, so since it's a table the cell will take the whole list row. 2. Also, the cell is no taking the full height of the list, so I can't find a way to draw a cell and a half (since 0.5 heightFactor doesn't start from the very start of the list row) – RT. Jul 02 '20 at 16:24