Skip to content

Instantly share code, notes, and snippets.

@shawn-frank
Last active March 14, 2021 18:04
Show Gist options
  • Select an option

  • Save shawn-frank/52e8c00449061e41b9ba8fa063f4ee64 to your computer and use it in GitHub Desktop.

Select an option

Save shawn-frank/52e8c00449061e41b9ba8fa063f4ee64 to your computer and use it in GitHub Desktop.
Some lines of code for common customizations required for UITableView and UITableViewCell yet easy to forget
// Remove seperator lines between UITableViewCells in UITableView
// Reference: https://stackoverflow.com/questions/26653883/delete-lines-between-uitableviewcells-in-uitableview
var tableView = UITableView()
tableView.separatorStyle = .none
// Add spacing between UITableViewCell
// Reference: https://stackoverflow.com/questions/1369831/eliminate-extra-separators-below-uitableview
// Inside UITableViewCell subclass
override func layoutSubviews() {
super.layoutSubviews()
contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0))
}
// Eliminate extra separators in UITableView
// Reference: https://stackoverflow.com/questions/1369831/eliminate-extra-separators-below-uitableview
var tableView = UITableView()
tableView.tableFooterView = UIView()
// Remove the cell highlight color of UITableView
// Reference: https://stackoverflow.com/a/2787101/1619193
// Inside UITableViewCell subclass
override func layoutSubviews() {
super.layoutSubviews()
selectionStyle = .none
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment