Custom UICollectionViewLayout With Equal Inter-Item Spacing - uicollectionview

I'm having a difficult time figuring out how to designing what feels like it should be a fairly straightforward layout for my collection view. The heights of each cell are equal. The widths vary. The inter-item spacing should always be equal. The distance between rows should also always be equal. As more items are added, the width of the collection view will increase "intelligently." Let me give an example.
When I insert a new item, I will calculate the movement of items from rows (maybe the first item of row 1 moves up to row 0, maybe the first item of row 2 moves up to row 1. I then move it and the collection view grows wider.
I feel like this should be reasonably straightforward but I'm struggling.
Does anyone have some sample code that could help?

Have you tried this using UICollectionViewFlowLayout?
http://skeuo.com/uicollectionview-custom-layout-tutorial
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionViewFlowLayout_class/

Related

QML GridLayout fill doesn't work with span

(QtQuick 2.12 on Windows)
I'm having two related problems with GridLayout objects, both revolving around the use of Layout.fillWidth and Layout.fillHeight to get constant sized cells that their contents can anchor themselves to. I believe they also apply to RowLayout and ColumnLayout.
First, some of my children use Layout.columnSpan or Layout.rowSpan. But when I do this, even though the extra columns or rows are "occupied", the fillWidth or fillHeight doesn't seem to apply to the extra columns or rows. If this is W.A.D, I can't imagine why anyone would D. it this way--it looks like a bug to me. My "solution" is to create dummy items that force the other columns or rows to be filled. But this isn't without its problems. For instance, if I have a GridLayout with five columns, and I want to attach a child that is five columns wide (say as a title in the top row), and some of the columns are otherwise unoccupied, I can create a dummy Item with its Layout properties set to occupy those columns. But if I can't find a row in which there isn't something already spanning those columns, then the item clashes with one of the real items I want to display. This "works", but it produces an error message in the log, e.g., QGridLayoutEngine::addItem: Cell (0, 4) already taken.
BTW, I've found that I only need to insert enough dummy single-cell items to define all the grid boundaries. In the above example, I'd need a dummy in columns 1 and 3, because that's enough to define boundaries 0-1, 1-2, 2-3, and 3-4:
0 1 2 3 4
+---------------------------------------+
| colSpan = 5 |
+-------+-------+-------+-------+-------+
| dummy | | dummy |
+-------+ +-------+
Second, I specify a spacing on the GridLayout, but sometimes I want a double-wide gap, so I treat that as just another row or column that has nothing in it, and that should therefore have a zero height or width. But when I do that, I don't get the extra spacing--it acts as if the row or column just doesn't exist. Again, W.A.D.? But why? My "solution" is to place a dummy Item into the empty row with its Layout.fillWidth set, but obviously not Layout.fillHeight (or the opposite for an empty column).
These are pretty ugly hacks, they junk up the source code, and they're error-prone. Does anyone have any better ideas on how to do either of these things? Does anyone think they could be called bugs?

How to prevent only one row to be ordered-obj c

I have a table view. And I have multiple rows. While doing the reorder in editing mode, I want one row to stay in the first index all the time. So, if a user wants to swap a row with the first row, it shouldnt allow it. But it should be possible between the second and the third row.
How can I do this?
Thank you very much in advance
Set the first table view cell's showsReorderControl to NO and return NO in tableView:canMoveRowAtIndexPath: for the first row.
You can also implement the UITableViewDelegate method tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:
Here you can return an alternate index path if the proposed one is (0, 0).
Return Value
An index-path object locating the desired row destination
for the move operation. Return proposedDestinationIndexPath if that
location is suitable.
Discussion
This method allows customization of the target row for a
particular row as it is being moved up and down a table view. As the
dragged row hovers over a another row, the destination row slides
downward to visually make room for the relocation; this is the
location identified by proposedDestinationIndexPath.

Getting table height dynamically in iText

Is there a way of getting the height of a table before adding it to the document?
At first glance, I supposed that the number of rows in the table is enough to calculate height since I know the font size. However, some rows break that rule. For instance, one cell might store a paragraph that has more than one line. Hence, what I need to know is the total of the heights of every row.
Yeah, answer was not complicated.
In order to get the height of a table, one must set the width of the table first. In other words,
table.setTotalWidth((PageSize.A4.getWidth() - document.leftMargin()
- document.rightMargin()) * table.getWidthPercentage() / 100);
System.out.println(table.calculateHeights());
does give the height of the table.
If you want to get table's height dynamically you can do so only after you have added all the content to it. In order to make this work you have to set its fixed width property and locked width property first.
e.g.
table.setTotalWidth(555f);
table.setLockedWidth(true);
after this you can get table's height by using its table.getTotalHeight() method

Grouped table with image in first row (and section), the remaining ones having text with different length

I have a grouped table with two sections where I display text with different length and therefore cell height.
I have solved the problem with the different length/height with constrainedToSize in cellForRowAtIndexPath.
Now I want to add a section with one single row in which I want to show a picture.
How should I best implement that? (still a bit of a beginner with the Objective C)
I would guess that I would have to create an UIImageView and somehow link that to the cell, but my biggest concern is how do I do with the dequeueReusableCellWithIdentifier now that I will have two different type of cells?
Appreciate any advice that will help me save time from trial and error!
I ended up doing this:
Since my image is in my first section (and nothing else in that section) I divided my cellForRowAtIndexPath in to two parts with a simple if statement. One for the first section and one for the rest. Then I use two different dequeueReusableCellWithIdentifier and can set up two kind of cells. So far it work fine.

Getting position of pdfptable

in my document I am creating 3-4 pdfptables.
At design time I don't know the size of the tables. I need to place the 2nd table right after the first, but I dont know the position of the first (I can't calculate it because I dont know how big it is). How do I know where to place the second table?
You can figure out the total height of the table dynamically. After you use the WriteSelectedRows() function, you can call the .TotalHeight() property to find out how tall your table was (in points). Then figure out with some calculations where it ends and where the next one should begin.
That's right the table height and width is dynamically calculated, but you don't have to call WriteSelectedRows() function. You have to set either height or width.
In my case I had to first calculate that if font used can fill the page if not I had to dynamically change the font appropriately. So I find (by mistake) if you set TotalWidth the TotalHeight is automatically set/calculated.
Sanjay