Set dynamic subviews positions in UITableViewCell - ios

I am trying to implement the below views variations:
3.
So as you see in the first image we have price or pts and popular, in the second image we have popular and not available, and the last image we have them all, and whenever an option is no there the other option will replace its position.
It is hard to update constraints for each case and what if later we have more options
Any ideas or suggestion thanks.

First enable tableview dynamic row height. then set all the views in cell to top.Set the second row dynamic labels bottom anchor to cell bottom anchor using lessOrEqualTo.This configuration will adjust your cell height automatically.You don’t need to calculate it.

Related

How to set the on UITableView cell width different from the selection of segment button in objc on one view using only one cell

I Have a view in which a segment controller ,I have used with two selection.
So here I just want to increase the width of cell containing label with address on first selection rather decrease the width by second selection,and here I used one cell and also using autoresizing in it.
Views are attached in it.Please have a lookView on selection of second segment index 2
Views on selection of second segment index 1
I understand it as that you want the address to fill the space taken up by the price when there is no price to show, there I suggest to:
Use Constraints
You can set a constraint for space between the address label and the price label.
Then a constraint between the price label and the trailing margin.
On scenarios where you do not need the price, set it's width to 0 and the address will stretch to fill up the space.
And since you are reusing the cell, remember to reset the width in prepareForReuse of the cell.

In tableview i have 4 static cells. How do i make row height automatically calculated to fit the label inside and one manually

So i have four sections and one cell in each one of the sections in my static tableview. One of them is displaying a picture and for that one i manually calculate the ration and multiply it by the width and that way i get the correct height. I do that using the "heightForRowAtIndexPath".
I also have three other cells and each one has a label in it. The labels content is different each time since i'm segueing to it from a different cell so sometimes the cell should be big enough for 1 row of text and sometimes for more. How do i calculate/set that to happen automatically?
Also in my storyboard i have the constrains for the label set to be 8 point away from the right left and top, thats all the constrains that are on the label. I already tried setting the tableView.rowHeight to UITableViewAutomaticDimensions but that doesn't do anything. The rows just stay at the same height as they were set in the "heightForRowAtIndexPath" or the same as in the storyboard if that function is not implemented. Been trying to solve that for probably more then an hour now and still cant figure it out. Thanks for the help. Also i'm doing all of this in swift.
If you implement heightForRowAtIndexPath it will also override any value for the table view's rowHeight. So, in heightForRowAtIndexPath return UITableViewAutomaticDimension, and do the same in estimatedHeightForRowAtIndexPath too.
As long as your cell has a solid Auto Layout configuration, that's all it takes to make auto-sizing cells work.

TableViewCell with multiple columns

I have an application in which I want to have a tableView with custom tableViewCell that has five columns.
I want them to be like 20%, 30%, 15%, 20% and 15% of the whole cell's width, because I want my application to launch on iPhone and iPad.
What is the best way to do this?
Now I have created a tableViewCell prototype with 5 labels. I also added constraints to them but the width constraint is just a constant. Also when I added width constraints to labels, some collisions appeared there and I don't know how to fix them.
Here is a screenshot.
You can create table view cell with collection view. By that, you can get different part in cell as well as you can change each column width programmatically based on your needs.
Thanks
A table view has only one column and allows vertical scrolling only. link
If you want to use a few columns, you can use UICollectionViewController
I also added constraints to them but the width constraint is just a constant. Also when I added width constraints to labels, some collisions appeared there and I don't know how to fix them
To fix it change width constraints to be a multiplier of superview width.

Working with AutoLayout using UITableViewCell

I am working with autoLayout, I want to place a UIlabel on UITableViewCell, which should be always at the right of the cell and the center of right.
So here is what I want to achieve
So here you can see label named RC which I am talking about.
So here my cell height changes dynamically, so whatever be the text height I always want to be the center right.
2) Now as the cell height depends on the text of the label sentence. I want to make sure that if the cell has the default height and it will not decrease below it. It can increase to any height.
Select your label go to editor then select vertical center in container, also fix it using the trailing space from super view and set fit size to content and it should work. For dynamic tableViewCell height created using autolayout find the TUTORIAL. This will help you a lot.

Modifying a UICollectionViewFlowLayout to change cells positions

I need to slightly change the way FlowLayout draws cells.
I need to set the collection to scroll horizontally and I want to draw cells from left to right, moving to the next line when the width is completely filled and taking into account pagination.
Here some images to clarify my question:
This is the current behaviour of the FlowLayout:
this is what I'd like to obtain:
Some notes:
I need paginationEnabled = YES
I want to fix the rows to a maximum of 2
I have a fixed number of cells too.
Is there a way to achieve this behaviour working with a UICollectionFlowLayout? Or is this the case to create a totally custom UICollectionLayout?
I believe you would have to manually fill the cells checking the indexpath.row and also checking the width of each cell and self.view.frame.size.width

Resources