Different cell appearance for a single collection view - swift

I was asking here about the option to make a collectionView with multiple cells since our cells have a different appearance for different indexs.
The answer was not sufficient because other then just create multiple cells and pick one for every index, you have all sorts of problems such as :
How can you register multiple classes ? collectionView.register(FlowViewCell.self
Reusable cells system gets crazy because they are different
Every action you do on a cell must be identified with its class and it becomes a mess.
So, I am searching for another way to do so with a single cell.
What would be a good way to set different buttons in the same position of a cell, and show/enable a different button with different indexes ?
So for index 1 I have 2 circle buttons, and for index 2 I have one large wide button? if you just put them on the same spot and hide one you get a strange design.

The answer you linked is what you are looking for.
We use 4 different types of cell in our app and we don't have any problem with it.
You don't have to register multiple classes, you can all create them in your storyboard (inside the collectionview), the system will register the classes for you.
And then you call the cells like explain in the answer.
The hard part is having different sizes, we only have two (large cell and square cell, so two square cells fit on the same level), more than that would be tricky, especially different height.
But apart from that you can have different content on each cell without any problem.

Related

Nattable Cell with Multiple combination of images

We have a requirement to visualize a state of the cell.
Each cell represents user's DB CRUD access so each cell has four boolean flags for create, read, update and delete. To visualize, each cell should show four images with each image showing state of that flag.
We defined 8 labels (CREATE, NO_CREATE, READ, NO_READ etc) and adding these labels based on underlying model. So at any time, each cell will have 4 labels. We want to show 4 images in each cell with each image showing the state of corresponding flag.
Based on the research and from Dirk's suggestion, CellDecoratorPainter is the preferred approach. But each cell with a label is associated with one cell painter (in this case CellDecoratorPainter) so how do we use that to render combination of these images?
One approach I could think of is, instead of creating individual labels for READ, NO_READ etc., create 4x4x2 labels like READ_CREATE_UPDATE_DELETE, NO_READ_CREATE_UPDATE_DELETE and associate each of these labels with one cell painter decorator to paint series of images accordingly.
Not sure if that is the only possible approach. If any of you come across this type of situation, can you please share some thoughts?
PS: This is posted at Eclipse forums at https://www.eclipse.org/forums/index.php/m/1782700/#msg_1782700
It is suggested that we use custom image painter to achieve this as explained at https://www.eclipse.org/forums/index.php/m/1782739/#msg_1782739.
Snippet of response is
You could implement a custom ImagePainter that inspects the cell
labels and draws images based on the labels in the label stack. Or
stack CellPainterDecorators so that every decorator has an image as
decoration that is only painted in case of the cell label, and has
another decorator as base painter.
But honestly, writing a custom ImagePainter that inspects the labels and draws the images on occurence of a label seems to be more
intuitive.
We implemented CombinationImagePainter to achieve this and is available at https://gist.github.com/brsanthu/cd2f91da7777aa994e011f7acedd900a if you are interested.
We had a similar requirement wherein an image was to be displayed at the start and at the end. Almost the way you showed however we extended the AbstractTextPainter class and wrote the implementation according.

AutoLayout of Custom Accordion/Collapsible UITableViewCell

I would like to build a TableView where when the user clicks on a cell it expands to show more information. My question is how do I use Autolayout to arrange the multiple items in each cell.
Each cell will always be the same size, whether it is collapsed or not, so the sizing isn't dynamic.
The first problem I have is how to use Autolayout to arrange all the items in the cell. Before Xcode 7 I was successfully using Autolayout where I would pick a label-button-view to arrange, click Editor > Align > Trailing/Leading/Top Space, to.. etc. This is now greyed out and I don't know how to replace my old strategy.
Each cell has two rows of items. The first row shows all the time, the second only shows on collapse. Below is a picture of how the cell will look when it is collapsed:
The first row is a bit trickier because outlet1 and outlet 2 will have variable sizes. I would like 'label' to come right after label1, no matter how long or short that outlet happens to be. As arranged currently, there is a variable amount of space between the two.
What I'm looking to achieve in row 1 is basically exactly like Venmo:
Notice how 'paid' conforms to the size of the two names in the first row.
The second row has two buttons and an outlet which will always be the same size.
To sum up - how can I layout these elements in the UITableView for iphones4 thru 6S - and then how do I make this cell a collapsible cell? The construction of these cells seem to work as a system, not isolated from the whole - which is why this is a 2-part question.
is this what you want to achieve?

How many UILabels can be added to a View

I want to add about 300 grids to a UIView,It is OK if I use 300 UILabels?
Or,besides UILabel,any better way to deal with it?
Grid means what you can make a UITableView with 300 rows and you can make any number of labels in your UIView
Perhaps start here. Other than that, I don't see a problem with UILabels, with that count, it might get slower though. Imagine how many objects you will be rendering...
If you create a UITableView with reusable cells, only the visible cells will be populated at any one time, so only those UILabels (assuming one or more per cell) will actually exist at any one time. Not a problem.

manual layout of a custom UITableViewCell for this approach?

Background - I have a custom UITableViewCell layout. Each cell will have a number of UILabels with a variable number of rows of UILabels. For the sake of argument conside 3 columns of UILabels (different widths), and a variable number of rows depending on the data.
To best allow for content view size changes (e.g. edit mode, change in orientation etc) I was going to manually layout each of the UILabels in the cell in the "layoutSubviews" method, effectively setting up their exact positions. I thought this way they will be laid out appropriately for events such as EDIT mode, orientation change etc.
Question - I'm wondering whether from a performance point this is the best approach? Or should I be looking at somehow predefine the UILabel rows, one predefined set for portrait mode and another set for landscape mode? (not exactly sure of how this would be done, but I'm trying to describe an approach where the layout would not have to be re-calculated when orientation changes etc)
thanks
suggestion by RickMaddy elsewhere was good:
"Why have a variable number of rows of labels in a single table row? Have one row of labels per table row. Then the problem is easier and performance won't be an issue."

Select one table cell and have multiple cells momentarily highlight

I have related items in adjacent table cells. When either of the related items is selected, before going to the detail view, I would like the momentary cell selection highlight to show both (or in some cases 3) cells highlighted to alert the user of the relationshp.
This a purely a "nice to have" cosmetic feature.
Any help appreciated.
In the method called when the user selects a row you can use:
[cell setSelected:YES];
One way to get the cell would be using tableView:cellForRowAtIndexPath method (correct me if I'm wrong).
* FOLLOW-UP TO Shaggy Frog *
I appreciate your comments.
For some reason, I can't add a comment to or edit my own original question so I am editing my follow-up.
May I have an opinion on the following. Since the 2 highlightd cells would always be adjacent and the data related, it makes sense that the detail view contain details for both cells. However your point is valid and I don't want to get rejected.
Instead of 2 cells, if for the "related cells" I were to double the height of those cells, draw a horizontal line half way between (to make the 2 "subcells" of 44 pixels in height looking just like 2 cells) and place the data in subviews so the result looks exactly the same as 2 cells but it would actually be 1 cell. Selection of one of my "subcells" would then highlight 2 "subcells" which is the entire cell - same effect but 1 cell.
Do you think that would pass?
And of course the biggest advantage is that I know how to do this versus the multi-cell highlighting which doesn't seem possible.