Reputation: 4253
I've UITableView and I wants set corner radius and a margin/padding to Top/Right/Left/Bottom. But, if I try set this, my layout is messing. And, when I try: cell.cellView.layer.cornerRadius = 20.0
fires nil pointer exception.
My layout is like this:
A example of I like that my layout be:
I wants that my cells stay "floating" with corner radius and margins, without mess my layout builded.
Also about UITableView, how I remove the unused cells? I have only 3 cells, but TableView shows all cell possibles, leaving others cell not useds.
Also (4): Why my cells appears united? This not appears "floating"
Upvotes: 3
Views: 4919
Reputation: 4552
For your require layout do below steps.
Add UIView
in you cell
contentView
with Leading, Top, Trailing, Bottom Constraint. Like (15, 10, 15, 10)
Select that UIView
and check Clip to Bounds
checkmark.
Add your required UI inside that UIView
.
Set UIView
cornerRadius
inside layoutSubviews()
inside your cell
file
And to remove UnUsed cell
write this line your viewDidLoad
-> self.tblVW.tableFooterView = UIView.init(frame: .zero)
Here is demo Link: https://www.dropbox.com/s/815loyp20r0oetf/Demo.zip?dl=0
Upvotes: 2
Reputation: 732
I am assuming you are taking a view inside table view cell on which your all content is present. that is why your using cell.cellView
what you need here is that just add this line too if in case you are missing.
cell.cellView.clipToBounds = true
This should work.
In case you are not taking an UIView inside cell content view then follow this steps.
Upvotes: 0