Change distance between cells

Hey guys. I want to change the distance between cells in my table view, but I can't find a way to do this. I did try to simply have many sections instead of rows, but it messed up the data source. Does anyone have any clue how to do this?

Answered by Mr. Bruce Wayne in 237403022

FOUND A SOLUTION! If I make ANOTHER content view for the cell, send that one to the back, make the origianl view transparent, and set the cell color to the same color as the background, it works! I just have to fine tune the dims. I haven't tested this on any other devices, that is from iPhone to iPad. So if I have any issues, I'll be sure to post them. Thanks for the answers guys!

Do you use custom cells ?


If so, you could just make the cell view taller or smaller.


Do you want to change the distance programmatically ?

Look at the 2 func :

func tableView(NSTableView, heightOfRow: Int)

// Asks the delegate for the height of the specified row.

func tableView(NSTableView, sizeToFitWidthOfColumn: Int)

// Asks the delegate to provide custom sizing behavior when a column’s resize divider is double clicked.

Afraid that won't work for me. I'm trying to expose the background color between the cells.

Is there a way to change the separator thickness?

If you're talking about NSTableView, there's an "intercellSpacing" property, which you can set programmatically, or via IB. I don't see any way of setting the separator thickness, but I don't think you need that if intercell spacing does what you want.

IB?

Accepted Answer

FOUND A SOLUTION! If I make ANOTHER content view for the cell, send that one to the back, make the origianl view transparent, and set the cell color to the same color as the background, it works! I just have to fine tune the dims. I haven't tested this on any other devices, that is from iPhone to iPad. So if I have any issues, I'll be sure to post them. Thanks for the answers guys!

IB == Interface Builder

UPDATE:


So far it's working. The only issue I've come across is when you rotate the device you have to reset the view's width. Haven't found a solution yet, except for disabling device rotation.

Found a bug and solution. I was having an issue where the center of the cell's content view was MOVING on an iPhone 8 Plus! Don't know why, but the solution was to make the center of my extra view (the width of the screen divided by 2, half of the extra view's height). Not sure why the scree width has to be divided, but that's what got it to work. Here's the script:


let rectangle = CGRect(x: 0, y: 0, width: parent.tableView.frame.width, height: 86)
 let myView : UIView = UIView(frame: rectangle)
myView.center = CGPoint(x: (UIScreen.main.bounds.width)/2 , y: 47)
myView.backgroundColor = UIColor.white
myView.tag = 821
self.contentView.addSubview(myView)
self.contentView.sendSubview(toBack: myView)      
Change distance between cells
 
 
Q