In a tableview one cell overlaps the cell displayed under it when initially presented. When you scroll down until the top cell is not longer visible and then scroll back up the cell are ok again.
I deactivated the separators with this line:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
The second cell has a view that fill it from top to bottom, that was a border radius. When the cells are initially presented the border is covert.
How can i fix the spacing of the tableviewCells when they are initially loaded? Can i set the z index the second cell, so that the second cell is above the first one?
I finally found that the constraint of the the top cells where causing the trouble. I found a workaround by storing the layout constraint in a property and adjusting the constant of the constraint as needed.
For "Can i set the z index the second cell, so that the second cell is above the first one?"
UITableViewCell is subclass of UIView so in table view delegate use this :
secondCell.layer.zPosition = 1;
Related
I am trying to make a custom TableViewCell for a tableview, and the size is 414x350. The problem I am having is when table view get loaded all the sizes are squeezed and not right. I have tried all of the followings:
Assigning row height from code
tableView.estimatedRowHeight = 350
tableView.rowHeight = UITableView.automaticDimension
Assigning row height from storyboard in tableview window
Assigning row height from storyboard in tableviewcell window
The result is still the same. Any help is appreciated!
For any cell's automatic row dimension to be calculated properly, in your Storyboard you must have a direct line of vertical constraints between every item that goes all the way from the top to the bottom. If you set the constraints yourself, same thing applies.
Don't assign any row heights, except the estimated.
I have a question - how to add a view as a subview of UITableViewCell but on top of all other views?
Here is an example of what I'm trying to achieve:
The image should scroll with the cell - save it's position relatively to scroll view (table view in this case).
If the cell is to small in height then the emojis overlay will be cut by the cell on top of current one, so how can I add this emojis overlay as a subview but at the same time display it on top of every cell? I've tried bunch of variants for now and nothing is working for me.
Just adding as a subview of the current window is not working for me because this overlay should scroll with the cell.
Tried code:
view.layer.zPosition = 5
cell.contentView.insertSubview(view, aboveSubview: cell.contentView)
cell.contentView.bringSubview(toFront: view)
UIApplication.shared.keyWindow?.addSubview(view)
Try to set cliptobouds = false for your cell.contentview and cell itself.
Otherwise if it is single overlay which you want to be on top of every cell then better implement UISrollViewDelegate and position the overlay accordingly.
I have a TableViewCell which have the border at the surrounding.So what some space at the bottom of each cell.
Here is what I want :
I see a lot of question is work for cell which doesnt have any border.What I want is the space is outside the border at the bottom of every cell.
Now my cell is look like this
So how can I achieve the output that I stated in first picture?
It's easily accomplished with static/dynamic tableView cells & don't give the border to the cell itself but to the subview named TopView
tableViewCell
->ContentView
->TopView ---- with border height(static/dynamic)
->DownView transparent ---- height(10)
with
tableView.separatorStyle = .none
I am having a custom cell where I add a UIImageView as a subview for the cell's contentView.
This UIImageView is placed outside the boundaries of the cell which results with image appearing underneath the table view separator as follows:
I wish that the image will override the table view separator as follows:
How can I do that?
That you can't do with tablview's separator. You first need to hide tableview's separator (i.e set seperator to none from IB or you can set to none by code also).
Take UIView with same width of separator and with height = 1 or 2 if want thick separator. And put it to the end of contentview of cell.
The easiest way is to default separators in tableview and add a simple uiview line as a subview to your cell below your image view.
I have a custom UITableViewCell subclass with width of 300.
Since the cell is 20pt shorter than the table view, When the cells get loaded, its placed on the left most position, is there a way to center this custom cell to the tableview's center?
I tried cell.center = self.tableView.center in cellForRowAtIndexPath, but it wont work. any idea?
You can pad your custom cell with 10px to the left so it will only appear to be centered, so you just make the width 310 and move everything else inside by 10 px.
a) Resize your UITableView to 300 and center it.
or
b) Make your cell's width same as UITableView's width. Make your custom cell's background color clearColor. Add one more view to your custom cell subclass that will contain every other view and add every view in that view. Think of this like an illusion where the cell is actually wider but it's contents are centered in a fake view.