Styling
Customise colours, fonts, spacing, and visual appearance of your data table.
SwiftDataTables provides multiple levels of styling control: configuration properties for global settings, per-cell callbacks for conditional styling, and complete cell replacement for custom layouts.
Per-Cell Styling
The defaultCellConfiguration closure is called for every cell as it's displayed. Use it to customize fonts, colors, and appearance based on the cell's value, position, or whether its column is currently sorted.
The closure receives four parameters:
cell— theDataCellbeing configured (access.dataLabelfor the text label)value— theDataTableValueTypefor this cell (use.stringValue,.doubleValue, etc.)indexPath— the cell's position (.section= row,.item= column)isHighlighted—trueif this cell's column is the current sort column
var config = DataTableConfiguration()
config.defaultCellConfiguration = { cell, value, indexPath, isHighlighted in
// Custom font for all cells
cell.dataLabel.font = UIFont.systemFont(ofSize: 14, weight: .medium)
// Red text for negative numbers
if let number = value.doubleValue, number < 0 {
cell.dataLabel.textColor = .systemRed
} else {
cell.dataLabel.textColor = .label
}
// Bold text in the sorted column
if isHighlighted {
cell.dataLabel.font = UIFont.systemFont(ofSize: 14, weight: .bold)
}
}Alternating Row Colors
Zebra striping improves readability for wide tables. SwiftDataTables uses two color arrays — one for regular columns and one for the currently sorted column (highlighted). Colors cycle through the array as rows alternate.
| Property | What It Colors | Default |
|---|---|---|
unhighlightedAlternatingRowColors | Cells in non-sorted columns | White / Light gray |
highlightedAlternatingRowColors | Cells in the sorted column | Light blue tints |
var config = DataTableConfiguration()
// Regular columns: subtle alternation
config.unhighlightedAlternatingRowColors = [
.systemBackground,
.secondarySystemBackground
]
// Sorted column: tinted to stand out
config.highlightedAlternatingRowColors = [
UIColor.systemBlue.withAlphaComponent(0.08),
UIColor.systemBlue.withAlphaComponent(0.12)
]Use semantic colors (.systemBackground, .secondarySystemBackground) for automatic dark mode adaptation. Avoid hardcoded RGB values.
Sort Indicators
When a column is sorted, an arrow appears in the header (and optionally footer) indicating the sort direction. You can customize the arrow color or hide it entirely.
| Property | Effect | Default |
|---|---|---|
sortArrowTintColor | Color of the sort arrow | System blue |
shouldShowHeaderSortingIndicator | Show arrow in header | true |
shouldShowFooterSortingIndicator | Show arrow in footer | true |
var config = DataTableConfiguration()
// Match your app's accent color
config.sortArrowTintColor = .systemIndigo
// Hide the footer arrow (header only)
config.shouldShowFooterSortingIndicator = falseSpacing and Heights
Control the vertical dimensions of rows, headers, footers, and the gaps between them.
| Property | What It Controls | Default |
|---|---|---|
rowHeightMode | Height of data rows (.fixed(CGFloat) or .automatic) | .automatic |
heightOfInterRowSpacing | Vertical gap between rows in points | 0 |
heightForSectionHeader | Height of the column header row | 50 |
heightForSectionFooter | Height of the column footer row | 50 |
heightForSearchView | Height of the search bar area | 44 |
var config = DataTableConfiguration()
// Fixed row height for uniform appearance
config.rowHeightMode = .fixed(52)
// Add subtle separation between rows
config.heightOfInterRowSpacing = 1
// Taller header for emphasis
config.heightForSectionHeader = 56Visibility Options
Show or hide optional UI elements. Hiding elements you don't need creates a cleaner interface.
| Property | What It Shows/Hides | Default |
|---|---|---|
shouldShowSearchSection | The search bar above the table | true |
shouldShowFooter | The column footer row | true |
shouldShowVerticalScrollBars | Vertical scroll indicator | true |
shouldShowHorizontalScrollBars | Horizontal scroll indicator | true |
var config = DataTableConfiguration()
// Hide search if filtering is handled externally
config.shouldShowSearchSection = false
// Hide footer if you don't need column summaries
config.shouldShowFooter = falseFloating Behavior
Floating elements stay visible while scrolling. The header floats by default so column names remain visible; you can enable the same for footers and the search bar.
| Property | Effect When true | Default |
|---|---|---|
shouldSectionHeadersFloat | Header sticks to top during vertical scroll | true |
shouldSectionFootersFloat | Footer sticks to bottom during vertical scroll | false |
shouldSearchHeaderFloat | Search bar sticks to top | true |
var config = DataTableConfiguration()
// Keep footer visible for running totals
config.shouldSectionFootersFloat = truePutting It Together
Here are two complete examples showing how these properties combine.
Corporate Theme
Professional appearance with brand colors and comfortable spacing:
var config = DataTableConfiguration()
// Brand-tinted sorted column
config.highlightedAlternatingRowColors = [
UIColor.systemIndigo.withAlphaComponent(0.08),
UIColor.systemIndigo.withAlphaComponent(0.12)
]
config.sortArrowTintColor = .systemIndigo
// Comfortable row height with subtle separation
config.rowHeightMode = .fixed(48)
config.heightOfInterRowSpacing = 1
// Prominent header
config.heightForSectionHeader = 56Minimal Style
Clean, borderless appearance that lets the data speak:
var config = DataTableConfiguration()
// No zebra striping — solid background
config.unhighlightedAlternatingRowColors = [.systemBackground]
config.highlightedAlternatingRowColors = [.systemBackground]
// Hide all optional chrome
config.shouldShowFooter = false
config.shouldShowSearchSection = false
config.shouldShowVerticalScrollBars = false
config.shouldShowHorizontalScrollBars = false
// No gaps between rows
config.heightOfInterRowSpacing = 0